Skip to content

Instantly share code, notes, and snippets.

@AlexeyRaga
Last active December 15, 2015 03:29
Show Gist options
  • Save AlexeyRaga/5194578 to your computer and use it in GitHub Desktop.
Save AlexeyRaga/5194578 to your computer and use it in GitHub Desktop.
Extending String in typescript
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