Closed
Description
TypeScript Version:
2.8.0-dev.201802213
Search Terms:
conditional, inference, constraint
Code
type MustBeString<T extends string> = T;
type EnsureIsString<T> = T extends MustBeString<infer U> ? U : never;
type Test1 = EnsureIsString<'hello'>; //'hello'
type Test2 = EnsureIsString<42>; //42
Expected behavior:
Test2
has type never
Actual behavior:
Test2
has type 42
, even though typescript correctly infers that U
must be a string
in the conditional true branch.