Skip to content

Instantly share code, notes, and snippets.

@jbrechtel
Created April 28, 2016 18:19
Show Gist options
  • Save jbrechtel/766161f66b50a30aa90551a4ac5e3002 to your computer and use it in GitHub Desktop.
Save jbrechtel/766161f66b50a30aa90551a4ac5e3002 to your computer and use it in GitHub Desktop.
Typescript Structural Typing
class Thing implements IThing {
constructor(private name: string) { }
public doStuff(): string {
return "hello";
}
}
interface IThing {
doStuff(): string
}
function workWithThing(t: IThing): string {
return t.doStuff();
}
workWithThing({ doStuff: () => "HI THERE"});
class Thing {
constructor(private name: string) { }
public doStuff(): string {
return "hello";
}
}
function workWithThing(t: Thing): string {
return t.doStuff();
}
workWithThing({ doStuff: () => "HI THERE"});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment