javascript - 如何扩展 TypeScript 接口并对其进行非部分化
问题描述
我希望能够做到以下几点:
interface Partials {
readonly start?: number;
readonly end?: number;
}
interface NotPartials extends Partials /*incorporate Unpartialing somehow */ {
readonly somewhere: number;
}
那么,NotPartials 将是:
readonly start: number;
readonly end: number;
readonly somewhere: number;
注意现在需要 start 和 end 。这可能吗?
解决方案
好吧,这很愚蠢。
我认为在 TypeScript 2.8 中这是可能的:
interface Partials {
readonly start?: number;
readonly end?: number;
}
interface NotPartials extends Required<Partials> {
readonly somewhere: number;
}
推荐阅读
- python - 用两个不同的字符串替换子字符串,具体取决于它们的位置
- python - 我的程序使用 IMDBpy 有没有一种方法可以使用该程序而无需在使用之前手动安装 IMDBpy?
- java - 如何在可点击的跨度小部件中从 Firestore 中检索图像?
- java - 如何使用图形在 JPanel 上绘图
- php - SQLSTATE[HY000] [2002] mac中没有这样的文件或目录迁移问题
- c - 在C中以正确的顺序打印链表
- javascript - Internet Explorer 11 中的 JavaScript ES6
- excel - 将 Ms 项目文件导出到 Excel 的宏
- c++ - 应该显示“Hello World!”的代码不显示任何内容
- python - 通过 piexif 读取 EXIF 信息时随机字母的重要性