考虑一个外部(npm)模块extmod
,在其声明文件中公开以下接口:
interface Options {
somevar?: string;
suboptions?: {
somesubvar?: string;
};
}
如何通过模块扩展在somesubvar2
内添加属性suboptions
?
我在extmod.d.ts
文件中尝试了以下操作:
declare module 'extmod' {
interface Options {
suboptions?: {
somesubvar2?: string;
};
}
}
但是它会引发以下错误:
error TS2687: All declarations of 'suboptions' must have identical modifiers.
error TS2717: Subsequent property declarations must have the same type. Property 'suboptions' must be of type '<SNIP>', but here has type '{ somesubvar2: string; }'.
答案 0 :(得分:-1)
如何在模块的子选项内添加属性somesubvar2 增强?
在您的示例中,您将类型suboptions
从<SNIP>
更改为{ somesubvar2: string; }
您可以使用其他属性来修补<SNIP>
类型。