为什么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也不能通过编译
慕斯王
相关分类