The following prototype method for a JavaScript String in Typescript 2.0.3:
interface String {
splice(start: number, delCount: number, newSubStr: string): string;
}
String.prototype.splice = function(idx: number, rem: number, str: string): string {
return this.slice(0, idx) + str + this.slice(idx + Math.abs(rem));
};
throws the error:
error TS2339: Property 'splice' does not exist on type 'String'.
despite my interface. It seems to work fine in the playground. I am just running tsc on that file with no options. Why isn't this working?
tsc(2.0.3and1.8.10) on a file containing only your code and it worked just fine. Are you sure that this is all?