Let’s say I want to add the following prototype to the String class.
String.prototype.beginsWith = function (string) {
return(this.indexOf(string) === 0);
};
I need to add beginWith to lib.d.ts otherwise it won’t complile:
declare var String: {
new (value?: any): String;
(value?: any): string;
prototype: String;
fromCharCode(...codes: number[]): string;
//Here
}
The file is locked and I can’t edit it.
I release I can just declare var String: any before the call but can I have it built in?
You don’t need to modify the lib.d.ts instead extend the String interface first, then include the new method to the prototype chain of the object you wish to extend.
For e.g.
Then implement the new functionality and add it to the prototype chain
Now you will get the intellisense in the calling code and works as expected.