Neal Burger
Aug 22, 2019 · 1 min read

You probably should rework the article a little:

const fooBar = sum<{foo: string}> (1,2); will be undefined. also fooBar will still be the type ‘number’ -

The only thing that you did was misinform the TypeScript Compiler what is really going on. Which will exactly lead to a TypeError during Runtime.

Also you get unexpected behavior when you pass in sum({a:1}, {b:2})

‘Generics’ are not needed for sum. it is plain as simple:

const sum = (a: number, b: number): number => a+b;

You need a better example of where Generics are useful.

    Neal Burger

    Written by