Skip to content

Instantly share code, notes, and snippets.

@ChuckJonas
Created March 31, 2018 00:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ChuckJonas/270c524af160de204d4eeece864c287f to your computer and use it in GitHub Desktop.
Save ChuckJonas/270c524af160de204d4eeece864c287f to your computer and use it in GitHub Desktop.
introtype.ts
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