我想从类型中排除一个属性.我怎样才能做到这一点?
比如我有
interface XYZ {
x: number;
y: number;
z: number;
}
Run Code Online (Sandbox Code Playgroud)
我想排除属性z得到
type XY = { x: number, y: number };
Run Code Online (Sandbox Code Playgroud) 有没有办法更改*.d.tsintype中定义的接口属性的类型?
例如:接口in x.d.ts定义为
interface A {
property: number;
}
Run Code Online (Sandbox Code Playgroud)
我想在我写的typescript文件中更改它
interface A {
property: Object;
}
Run Code Online (Sandbox Code Playgroud)
甚至这会起作用
interface B extends A {
property: Object;
}
Run Code Online (Sandbox Code Playgroud)
这种方法会起作用吗?当我尝试使用我的系统时,它无法正常工作.只是想确认它是否可能?
由于当前的语言限制,这可能无法实现,但我使用的是最新的 TS (1.8.10) 并且遇到了 ui-grid 类型的问题。该isRowSelectable物业上IGridOptions被定义为一个可选的布尔但文件说,这是一个功能(它是)。我试图将布尔属性覆盖为返回布尔值的函数。
通常,我只是扩展打字界面并执行我需要的操作,但这在这种情况下不起作用。这是我所拥有的:
interface ISelectionGridOptions extends IGridOptions {
isRowSelectable: (row: IGridRowOf<Profile>) => boolean;
}
Run Code Online (Sandbox Code Playgroud)
中的相关字段IGridOptions是:
export interface IGridOptions {
...
isRowSelectable?: boolean
...
}
Run Code Online (Sandbox Code Playgroud)
我得到的错误是:
(41,11): error TS2430: Interface 'ISelectionGridOptions' incorrectly extends interface 'IGridOptionsOf<any>'.
Types of property 'isRowSelectable' are incompatible.
Type '(row: IGridRowOf<Profile>) => boolean' is not assignable to type 'boolean'.
Run Code Online (Sandbox Code Playgroud)
缺少修复核心类型定义,有没有办法在我的代码中解决这个问题?