Skip to content

Instantly share code, notes, and snippets.

Created August 9, 2020 11:48
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save jaycosaur/5ee27791cf991dee5939370ba416f270 to your computer and use it in GitHub Desktop.
Composable types [typescript] - Typescript to Python field guide
interface Animal {
length: number;
eat: (food: string) => void;
// Fish extends the Animal interface
interface Fish extends Animal {
swim: (howLong: number) => void;
// fish implements the Fish interface implicitly and does not directly reference it
const fish = {
length: 12,
eat: (food: string) => console.log(`Eating ${food}`),
swim: (howLong: number) => console.log(`Swimming for ${howLong}`),
function doSomethingFishy(what: Fish) {"worms");
doSomethingFishy(fish); // this is ok!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment