Created
March 31, 2018 00:43
-
-
Save ChuckJonas/270c524af160de204d4eeece864c287f to your computer and use it in GitHub Desktop.
introtype.ts
This file contains 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
interface Foo{ | |
twittle: string; | |
doBarStuff(b: Bar): number; | |
fooOptional?: number | |
} | |
interface Bar{ | |
one: number; | |
two: string; | |
} | |
let foo: Foo = { | |
twittle: 'abc', | |
doBarStuff: (bar) => { return bar.one + bar.two.length }, | |
fooOptional: 123 | |
} | |
let bar = { | |
one: 10, | |
two: 'hello world' | |
} | |
let fooKeyStore: { [index: string]: Foo } = {} | |
fooKeyStore['firstFoo'] = foo; | |
fooKeyStore['secondFoo'] = { | |
twittle: 'dcf', | |
doBarStuff: (bar) => { return bar.one / bar.two.length } | |
} | |
let bars = [ | |
bar, | |
{ | |
one: 20, | |
two: 'hello universe' | |
} | |
] | |
function fooBar(foo: Foo, bars: Bar[]) { | |
let barsTotal = 0; | |
bars.forEach(bar => { | |
barsTotal += foo.twittle.length + foo.doBarStuff(bar); | |
}); | |
return barsTotal; | |
} | |
fooBar(fooKeyStore['secondFoo'], bars); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment