Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/9.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
使用部分<;T>;在TypeScript中进行灵活的初始化_Typescript - Fatal编程技术网

使用部分<;T>;在TypeScript中进行灵活的初始化

使用部分<;T>;在TypeScript中进行灵活的初始化,typescript,Typescript,我试图在构造函数中使用init参数的Partial类型,使初始化更加灵活。这是我的密码: export class Team { id: string; name: string; public constructor(init?: Partial<Team>) { } } const team = new Team({}); 导出类团队{ id:字符串; 名称:字符串; 公共构造函数(初始化?:部分){ } } const team=新团队(

我试图在构造函数中使用
init
参数的
Partial
类型,使初始化更加灵活。这是我的密码:

export class Team {
    id: string;
    name: string;

    public constructor(init?: Partial<Team>) {

    }
}

const team = new Team({});
导出类团队{
id:字符串;
名称:字符串;
公共构造函数(初始化?:部分){
}
}
const team=新团队({});
但我不确定为什么会出现此错误:

Argument of type {} is not assignable to parameter type Partial<Team>
{}类型的
参数不能分配给参数类型Partial

代码对我来说很好。试过在命令行中编译,但我的IDE仍然给我那个错误,所以它是一个和IDE问题。