You need to enter assert Fooable to type T :
function simplifiedExample<T extends Fooable>(bars: string[]): T[] { return bars.map(bar => { return { foo: bar } as T; }) }
( code on the playground )
The reason is that T not Fooable , it just extends it, but may have additional properties, for example:
interface Mooable extends Fooable { moo: string; } simplifiedExample<Mooable>(["a", "b", "c"]);
In this case, T is Mooable , but { foo: bar } does not satisfy this, so you need to enter cast.
source share