jkchao / typescript-book-chinese

TypeScript Deep Dive 中文版
https://jkchao.github.io/typescript-book-chinese/
MIT License
6.51k stars 675 forks source link

CrazyClass 在实现 Crazy 时报错 #251

Open xindoucha opened 2 years ago

xindoucha commented 2 years ago

在《接口》这一节最后“注意”部分的示例有点问题。 CrazyClass 在实现Crazy时显示如下报错: image

zombiu commented 9 months ago

我也遇到这个问题,大佬 解决没!

zombiu commented 9 months ago

interface Crazy { new (): { hello: number; }; }

const CrazyClass = function() {

} as unknown as Crazy

// Because const crazy = new CrazyClass(); crazy.hello = 156 console.log(crazy); 问题解决了,就是不知道为啥要这样解决!