在index.ts中,我用一个可选的prop声明了一个对象,在index.d.ts中,我为此对象分配了一个接口,但打字稿似乎看不到此分配,并警告该属性在该类型上不存在。
向Obj对象添加类型的正确方法是什么?
// index.ts
import a from './a'
import b from './b'
const Obj = {
a, b
}
if (condition){
Obj.log = function(){} // Typescript: log does not exist on type {...}
}
// index.d.ts
declare interface IObj {
log (any): void;
}
declare const Obj: IObj;