问题
I'm trying to extend an existing interface of KendoUI which comes from a definition file. With interface merging this is normally straight forward but the interface I'm going to extend is in a specific global namespace "kendo.ui"
I'm ust trying to add "hideInEditor" propterty to the interface to the kendo.ui.GridColumn interface like this.
namespace kendo.ui {
export interface GridColumn {
hideInEditor?: boolean;
}
}
However, the compiler seems to have forgotten all about the orginal definitions and I can no longer access the kendo namespace as all types are missing. So apparently this is wrong. But what is the correct way to extend such an interface?
回答1:
Having the type definition files in the same folder doesn't do anything unless you somehow tell the compiler to look for them.
In your case I think you need this:
/// <reference path="./kendo.ui.d.ts" />
namespace kendo.ui {
export interface GridColumn {
hideInEditor?: boolean;
}
}
let obj: kendo.ui.GridColumn;
console.log(kendo.culture()); // ok
console.log(obj.format); // ok
console.log(obj.hideInEditor); // ok
Note the first line with the reference
.
来源:https://stackoverflow.com/questions/41101727/typescript-how-to-extend-an-existing-interface-in-a-globally-declared-namespace