typescript - 如何扩展命名空间的接口
问题描述
我做了以下命名空间
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
. 似乎没有任何Container
类型是继承的。
编辑:Container
是一个普通的 ts 类
奇怪的是这行得通,但我不明白为什么会这样而且界面不会
type Component = Container & {
dApplyProps?: (p: UnknownProps) => void;
dApplyLayout?: () => void;
}
解决方案
推荐阅读
- python - Scrapy:twisted.internet.error.ReactorNotRestartable 从运行 CrawlProcess()
- vue.js - VUE - 在 v-for 完成循环后调用函数
- bash - 在上下文中使用“-”有什么用:“echo $$ $BASHPID | cat -”?重击
- pascal - Free Pascal - 创建一个先前声明的元素/对象的数组
- javascript - 从 DarkSky API 请求返回的意外时间值
- c++ - 使用向量随机调用函数
- java - 使用 For 循环在 Java 中打印二维字符数组
- javascript - Javascript类返回私有变量而不是getter
- linux - 在当前任务完成后连续运行 shell 脚本的 Bash 或 systemd 方法
- python - 如何在具有检查条件的数据框中添加额外的列?