Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
typescript中合并对象的类型应该是什么?_Typescript - Fatal编程技术网

typescript中合并对象的类型应该是什么?

typescript中合并对象的类型应该是什么?,typescript,Typescript,我有 我的最后一个目标我希望它看起来像这样: export interface Game { startingTime?: string; minutes?: string; finished: boolean; homeTeam: string; awayTeam: string; score?: string; } export class Markets { constructor() { return {

我有

我的最后一个目标我希望它看起来像这样:

export interface Game {
    startingTime?: string;
    minutes?: string;
    finished: boolean;
    homeTeam: string;
    awayTeam: string;
    score?: string;
}    
export class Markets {
    constructor() {
        return {
            '1': '',
            x: '',
            '2': '',
            '1x': '',
            x2: ''
        };
    }
}
那么
游戏的类型应该是什么呢?
这并没有让eslint抱怨,但这是正确的吗

const games = [
  {...{ finished: true, homeTeam: 'Santa Rosa', awayTeam: 'Molinos El Pirata', score: '0-3' }, ...new Markets()},
  {...{ finished: false, minutes: '75', homeTeam: 'Chavelines', awayTeam: 'Deportivo Coopsol', score: '1-0' }, ...new Markets()}
];
对我来说,这看起来更正确:

games: Game | Markets[] = [];
但埃斯林特说:

games: Game & Markets[] = [];

可以将类型括在括号中,以便它们都应用于数组

(游戏与市场)[]


或者像@lleon建议的那样使用
Array

正确的类型应该是
Array
我觉得游戏与市场[]也应该起作用:)非常感谢,请添加它作为答案而不是评论,这样我就可以接受了。另外,你也可以使用
(游戏与市场)[
@ToddSkelton啊,好了,这样做是可能的,但它需要括号。谢谢!
Type 'never[]' is not assignable to type 'Game & Markets[]'.
  Type 'never[]' is missing the following properties from type 'Game': finished, homeTeam, awayTeamts(2322)