Closed
Description
TypeScript Version: 3.3.0-dev.20181201
Search Terms: Conditional Types, Intersection
Code
type NumTest<S> = S extends number ? string : never;
type Str<T> = NumTest<T & number>; // should be string, I would think?
function foo<T>() {
const x: Str<T> = "hello";
}
Expected behavior:
No errors. More narrowly, I expect T & number
to be understood as extending number
.
Notably, if I inline the definition of NumTest<S>
, i.e.
replace the above definition of Str with the following:
type Str<T> = (T & number) extends number ? string : never;
then the error below vanishes.
Actual behavior:
ex.ts:4:9 - error TS2322: Type '"hello"' is not assignable to type 'NumTest<T & number>'.
4 const x: Str<T> = "hello";
~
Found 1 error.
Metadata
Metadata
Assignees
Labels
No labels