Skip to content

Aliasing a type in a conditional type changes the resultΒ #48936

Closed
@marcj

Description

@marcj

Bug Report

πŸ”Ž Search Terms

any, alias, conditional type,

πŸ•— Version & Regression Information

All versions are effected.

⏯ Playground Link

Playground Link

πŸ’» Code

interface User {
    id: number;
    username: string;
}

type Q<T> = {a: keyof T & string };

type t1 = Q<any> extends Q<User> ? true : never;

type qAny = Q<any>;
type t2 = qAny extends Q<User> ? true : never;

πŸ™ Actual behavior

t1 is true, and t2 is never.

πŸ™‚ Expected behavior

Both, t1 and t2 should be the same and be never, because {a: string} extends {a: 'id' | 'username'} is false.
The only difference is that the left value of extends is for t2 an alias, but the same type as in t1.

Interesting might be that t2 was in v4.1 true as well, but started to get the right value in v4.2.

Maybe related to #31295

Metadata

Metadata

Assignees

No one assigned

    Labels

    Design LimitationConstraints of the existing architecture prevent this from being fixed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions