Skip to content

Instantly share code, notes, and snippets.

@valerysntx
Created October 4, 2016 23:31
Show Gist options
  • Select an option

  • Save valerysntx/51ef7646d6e50cd1e090e0fdfe6eaf5f to your computer and use it in GitHub Desktop.

Select an option

Save valerysntx/51ef7646d6e50cd1e090e0fdfe6eaf5f to your computer and use it in GitHub Desktop.
generics for template literal tag functions
class Greeter<T>
{
greeting: T;
constructor(message: T) {
this.greeting = message;
}
greet() {
return this.greeting;
}
}
class GreeterDecoder<T> extends Greeter<string>
{
constructor(message: string) {
super(message)
}
get(decoder: Function): string {
return decoder`${this.greeting}`
}
greet() {
return this.get(decodeURI).toString()
}
}
let greeter = new Greeter<string>("Hello, world");
let greeterDecoder = new GreeterDecoder<string>("Hello&nbsp;world!");
console.log(greeter.greet());
console.log(greeterDecoder.greet());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment