Skip to content

Instantly share code, notes, and snippets.

@vvakame
Created July 9, 2017 10:05
Show Gist options
  • Save vvakame/97203c38c6e44060c4621e45c1ed13b7 to your computer and use it in GitHub Desktop.
Save vvakame/97203c38c6e44060c4621e45c1ed13b7 to your computer and use it in GitHub Desktop.
open https://www.typescriptlang.org/play/ & paste this code.
interface Hello {
hello(): string;
}
interface Named {
name: string;
}
function parrot<T extends Named>(obj: T): T {
return obj;
}
parrot({
name: "TypeScript",
});
parrot({
name: "TypeScript",
age: 5,
});
parrot({
name: "TypeScript",
age: function () { },
});
parrot({
name: "TypeScript",
sayHello() {
console.log(`Hello, ${this.name}`);
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment