首页 > 解决方案 > 如何扩展命名空间的接口

问题描述

我做了以下命名空间

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()

但是我收到一条错误消息,someContainerMethodDante.Component. 我假设我不正确地扩展接口?它 100% 存在于Container. 似乎没有任何Container类型是继承的。

编辑:Container是一个普通的 ts 类

奇怪的是这行得通,但我不明白为什么会这样而且界面不会

type Component = Container & {
    dApplyProps?: (p: UnknownProps) => void;
    dApplyLayout?: () => void;
}

标签: typescript

解决方案


推荐阅读