typescript - 打字稿:扩展/覆盖类类型定义
问题描述
我正在使用来自另一个外部库的外部库的类型。为一些类提供的类型还不够,我想知道如何扩展/覆盖它们。
打字库的module.d.ts
:
declare module '@library/module' {
export class SomethingImportant {
constructor(props?: any);
}
}
我想像这样更新打字(来自我已经在我的代码中设置的打字文件):
declare module '@library/module' {
export interface ImportantProps {
name: string;
age: number;
}
export class SomethingImportant {
constructor(props?: ImportantProps);
}
}
该接口按我的预期导出,但在我的代码的其他地方,类型的props
类型没有强制执行。我可以做到new SomethingImportant({banana: true})
,打字稿不会抱怨。
我正在尝试做的事情可能吗?
解决方案
推荐阅读
- c - 使转义序列在字符串中可读
- r - 用缺失值绘制正确的颜色和有序因子
- c - 为什么第一个代码与第二个代码不同?
- react-native - 如何在 expo + react-native 初始化阶段运行 clojurescript 函数?
- html - 带有文本的 HTML/CSS - EMAIL
- python - 如何在 Python 中同步 rx 管道?
- linux - 如果在 bash 中使用超时时没有执行循环
- xcode - Xcode 间歇性地找不到 xcframework
- node.js - 玩笑测试不使用 dotenv 读取环境变量
- python - PySpark - 从数据框中删除第一行