TD Ingrey
TD Ingrey

Reputation: 1

Typescript Prototype issue

I am having an issue creating a prototype in TypeScript, when I use the method I get "TypeError: t.stringTesting is not a function"

below is the code.

extensions.ts

interface String {
    stringTesting() : string;
}

String.prototype.stringTesting = function (): string {
    return "testing"
}

in my Angular2 component I am using

var t: string = "";
t = t.stringTesting();
alert(t);

Upvotes: 0

Views: 79

Answers (1)

basarat
basarat

Reputation: 275849

t.stringTesting is not a function"

You need to make sure the extensions.js runs before any code that uses it.

Upvotes: 1

Related Questions