-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Closed
Labels
Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug
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:
Metadata
Metadata
Assignees
Labels
Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug