interface Counter { (start: number): string; interval: number; reset(): void; }function getCounter(): Counter { let counter = <Counter>function (start: number) { }; counter.interval = 123; counter.reset = function () { }; return counter; }
为什么上面接口规定 counter 函数返回string,但实际上counter 函数并没有返回,不报错
interface Counter { (start: number): void; interval: number; reset(): void; }function getCounter(): Counter { let counter = <Counter>function (start: number) { return '12'}; counter.interval = 123; counter.reset = function () { }; return counter; }
但是 我将接口和函数返回调换了一下就报错了
相关分类