Skip to content

extends operator with literal types #54050

Description

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

typeA={x:string}|{x:number}|{x: symbol}typeB={x:string}|{x:number}|{x: boolean}// ^ literal type heretypeC={x:string}|{x:number}typeX={x:string|number}// `X extends B` but not A or CtypeX_A=XextendsA ? "X extends A" : "X not extends A";// ^? X not extends AtypeX_B=XextendsB ? "X extends B" : "X not extends B";// ^? X extends BtypeX_C=XextendsC ? "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