作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个定义如下的接口(interface):
export interface Iface {
id: string;
foo: string;
}
我想创建一个接口(interface),它是 Iface
的一部分并将其导出。我试过了
export interface PartialIface = Partial<Iface>;
但是 typescript 提示部分错误。如果我将 interface
关键字更改为 type
它会起作用。为什么我必须将它声明为 type
别名而不是 interface
?
export type PartialIface = Partial<Iface>;
最佳答案
请看:
export interface Iface {
id: string;
foo: string;
}
export type PartialFace=Partial<Iface>
您还可以复制粘贴您的界面,并将所有属性设为可选:
export interface Iface {
id?: string;
foo?: string;
}
我不知道其他方法
关于typescript - 将接口(interface)导出为 Partial<OtherInterface>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64899894/
我有一个定义如下的接口(interface): export interface Iface { id: string; foo: string; } 我想创建一个接口(interface
我是一名优秀的程序员,十分优秀!