Skip to content

Conditional type doesn't think T & U extends U #28830

Closed
@jcreedcmu

Description

@jcreedcmu

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.

Playground Link

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions