Skip to content

Instantly share code, notes, and snippets.

@tanepiper
Created April 12, 2018 07:54
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 tanepiper/d29bcbbbe96bbd45de8f89a82549c68a to your computer and use it in GitHub Desktop.
Save tanepiper/d29bcbbbe96bbd45de8f89a82549c68a to your computer and use it in GitHub Desktop.
Type inference in typescript
const foo = function <T>(a: T, b: T[]): any {
return { a, b }
}
foo(6, 'di')
foo(6, [9])
foo<string>(6, 'di')
foo<string>('foo', 'di')
foo<string>('foo', ['di'])
foo<object>({}, [{}]) 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment