Skip to content

extends operator with literal typesΒ #54050

Closed as not planned
Closed as not planned
@dpohvar

Description

@dpohvar

Bug Report

πŸ”Ž Search Terms

πŸ•— Version & Regression Information

⏯ Playground Link

https://www.typescriptlang.org/play?ts=5.1.0-beta#code/C4TwDgpgBAglC8UDeAPAXAZ2AJwJYDsBzAXygB9l18BXAWwCMJtSLU0oMQGB7AG2IBQA0JCgAhBJUw4CJclJoMmLKVHrc+EAIb5BUfQcNHjJ0wYD05qAD0ovXMCZbeUEdAAWTCMPDQAwpJsWHhEKmyKjMxCblAAGoHowbLyEcoCllAABvEQKI74ACYY4plq1MBQ+NwVcNzYUH5CPqKxAPpwiDl5EIXFcAD8UABEXflFsENQ7COV1VC5Y31DANzpVvrW-dG+ca0SnfPdveJQgzMLPeNik9PxVRUXx9erGRtbzdBtAQeP4wFno0uxT8N2Gdzmv2BKzWBk221EMFa8UQcEhcVOw1RR3GsVBQzg90Oizi0NeNneMTESMkEjR8TOtOxxVxU2GEkJdNJ63J8P81MQATpGKGgqZJNZItmDzFuJe3LhQA

πŸ’» Code

type A = {x:string} | {x:number} | {x: symbol}

type B = {x:string} | {x:number} | {x: boolean}
                                       // ^ literal type here
type C = {x:string} | {x:number}

type X = {x:string | number}
// `X extends B` but not A or C


type X_A = X extends A ? "X extends A" : "X not extends A";
//   ^? X not extends A

type X_B = X extends B ? "X extends B" : "X not extends B";
//   ^? X extends B

type X_C = X extends C ? "X extends C" : "X not extends C";
//   ^? X not extends C

the bug is reproduced with any literal type instead of boolean

πŸ™ Actual behavior

X not extends A
X extends B;
X not extends C

πŸ™‚ Expected behavior

X not extends A
X not extends B
X not extends C

Metadata

Metadata

Assignees

No one assigned

    Labels

    Not a DefectThis behavior is one of several equally-correct options

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions