Typescript 类型脚本声明合并不起作用?
我想向现有接口添加新成员。但typescript不断抛出错误Typescript 类型脚本声明合并不起作用?,typescript,Typescript,我想向现有接口添加新成员。但typescript不断抛出错误 // foo.js export interface IOption { xOffset: number } 我的代码有什么问题?您需要为同一模块声明接口 修理 不能扩展现有接口,但可以使用以下技巧创建另一个同名接口: import * as foo from 'foo'; interface IOption extends foo.IOptions { yOffset: number } 谢谢是的,你说得对。如
// foo.js
export interface IOption {
xOffset: number
}
我的代码有什么问题?您需要为同一模块声明接口 修理
不能扩展现有接口,但可以使用以下技巧创建另一个同名接口:
import * as foo from 'foo';
interface IOption extends foo.IOptions {
yOffset: number
}
谢谢是的,你说得对。如果我必须使用
扩展,那么声明合并的意义是什么??它的用例是什么?我认为声明合并就像Ruby的类重新打开一样,但似乎不是。那又是什么呢?
import {IOption} from 'foo';
declare module 'foo' {
interface IOption {
yOffset: number
}
}
import * as foo from 'foo';
interface IOption extends foo.IOptions {
yOffset: number
}