Skip to content

Checked type of conditional type isn't matched for constraint in true clause unless the type parameter is constrained #31700

Closed
@sirian

Description

@sirian

TypeScript Version: 3.5.1

Code

type Ctor = new () => Date;

 // ERROR, WTF?
type Z1<T> = T extends () => Ctor ? InstanceType<ReturnType<T>> : never; 

// But here NO ERROR
type Z2<T extends any> = T extends () => Ctor ? InstanceType<ReturnType<T>> : never;


 // ERROR
type Z3<T> = T extends () => any ? InstanceType<ReturnType<T>> : never;

// NO ERROR again
type Z4<T extends () => any> = InstanceType<ReturnType<T>>;

Actual behaviour
type Z1<T> = T extends () => Ctor ? InstanceType<ReturnType<T>> : never; errors

Expected behaviour
type Z1<T> = T extends () => Ctor ? InstanceType<ReturnType<T>> : never; should be valid

More examples.
image

Playground Link:

Metadata

Metadata

Assignees

Labels

Working as IntendedThe behavior described is the intended behavior; this is not a bug

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions