Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Conditional Types: Type parameters with unknown constraint are not the most restrictive type when relating from any. #29674

Copy link
Copy link
@jack-williams

Description

@jack-williams
Issue body actions

TypeScript Version: master

A conditional type immediately resolves to the true branch when the condition is satisfied with type parameters instantiated at the most restrictive type---a type parameter with unknown constraint.

A type parameter with unknown constraint is not the most restrictive type in all cases: any may be assigned to any type parameter, but any may not be assigned to never.

Code `

type Contrived<T> = [any] extends [T] ? true : false; // true
type ContrivedConcrete = [any] extends [never] ? true : false; // false

Related Issues: These PR's #29338 #29437

To be honest, this issue is incredibly niche, and almost exclusively a result of any (that I currently know of). The behaviour is also consistent with how things work in other cases, such as:

function foo<T>(x: any): T {
    return x;
}
const a = foo<never>(3);

While the conditional behaviour is consistent with other cases where a type parameter can later be instantiated to never, I'm not sure anyone would ever want that behaviour in a conditional. Regardless of whether this is by design, a limitation, or a bug---I think it would be good to have this documented somewhere in the tracker.

Reactions are currently unavailable

Metadata

Metadata

Assignees

Labels

Needs InvestigationThis issue needs a team member to investigate its status.This issue needs a team member to investigate its status.

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.