Created
April 28, 2016 18:19
-
-
Save jbrechtel/766161f66b50a30aa90551a4ac5e3002 to your computer and use it in GitHub Desktop.
Typescript Structural Typing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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