Closed
Description
TypeScript Version: 2.9.2
Search Terms: generic infer contextual type
Code
const baz: (n: number) => number = (
// param `n` is correctly inferred to be `number` :-)
n => n
);
const identity = <T>(t: T) => t;
const bar: (n: number) => number = identity(
// param `n` is inferred as `any`, expected `number` :-(
x => x
);
Expected behavior: TypeScript should infer the generic T
in identity
from the contextual type.
Actual behavior: TypeScript infers the generic T
in identity
as any
!
Playground Link:
Related Issues: