为什么Class B可以通过Typescript编译(类型监测), Class C却不能通我希望Class B像Class C一样不能通过编译,Class C 编译会报错如下:Type '{ name: string; some: string; }' is not assignable to type 'Info'.
Object literal may only specify known properties, and 'some' does not exist in type 'Info'.
interface Info { name: string;
}
interface Person {
info(): Info;
}
class B implements Person {
info() { return { name: "li", some: "1",
};
}
}
class C {
info():Info { return { name: "li", some: "1",
};
}
}过, 期望Class B也不能通过编译
1 回答
慕斯王
TA贡献1864条经验 获得超2个赞
class B implements Person { info():Info { return { name: "li", some: "1", }; } }
- 1 回答
- 0 关注
- 771 浏览
添加回答
举报
0/150
提交
取消