Last active
December 15, 2015 03:29
-
-
Save AlexeyRaga/5194578 to your computer and use it in GitHub Desktop.
Extending String in typescript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface String { | |
format(): string; | |
} | |
String.prototype.format = function () { return this + "-formatted"; } | |
// Module | |
module Test { | |
// Class | |
export class Hello { | |
// NOTE: x is a string, not String | |
constructor (public x: string) { } | |
say() { | |
//note: .format method is visible by the language service | |
var val = this.x.format(); | |
alert(val); | |
} | |
} | |
} | |
var hello = new Test.Hello("alex"); | |
hello.say(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment