You can use the prototype to extend Array:
interface Array<T> {
remove(o: T): Array<T>;
}
Array.prototype.remove = function (o) {
// code to remove "o"
return this;
}
If you are within a module, you will need to make it clear that you are referring to the global Array<T>
, not creating a local Array<T>
interface within your module:
declare global {
interface Array<T> {
remove(o: T): Array<T>;
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…