Typescript 如何扩展名称空间';s接口
我创建了以下名称空间Typescript 如何扩展名称空间';s接口,typescript,Typescript,我创建了以下名称空间 declare namespace Dante { import Container from '$dante/components/Container'; interface Component extends Container { dApplyProps?: (p: UnknownProps) => void; dApplyLayout?: () => void; } } 我假设以下内容是有效的 const myCompon
declare namespace Dante {
import Container from '$dante/components/Container';
interface Component extends Container {
dApplyProps?: (p: UnknownProps) => void;
dApplyLayout?: () => void;
}
}
我假设以下内容是有效的
const myComponent: Dante.Component = /* .. */
myComponent.someContainerMethod()
但是,我得到一个错误,即someContainerMethod
在Dante.Component
上不存在。我假设我扩展接口不正确?它100%存在于容器中
。似乎没有继承任何容器
类型
编辑:Container
是一个普通的ts类
奇怪的是,这是可行的,但我不明白为什么它会和界面不一样
type Component = Container & {
dApplyProps?: (p: UnknownProps) => void;
dApplyLayout?: () => void;
}
看起来你没有将界面导出给我。尝试
导出接口
而不仅仅是接口
@r3wt似乎不起作用,导出所有内容,重新启动ts服务器,只有合并类型的方法有效。看起来你没有将接口导出给我。尝试导出接口
而不仅仅是接口
@r3wt似乎不起作用,导出所有内容,重新启动ts服务器,只有合并类型的方法才有效。