0

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);
1
  • Your code is working fine. You probably don't load this extensions.js at runtime Commented Aug 15, 2016 at 13:14

1 Answer 1

1

t.stringTesting is not a function"

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.