Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug in conditional types with union types: AProperty should be number instead of never #61025

Open
jerryyxu opened this issue Jan 23, 2025 · 1 comment
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@jerryyxu
Copy link

πŸ”Ž Search Terms

infer T in conditional type union returns never

πŸ•— Version & Regression Information

I started encountering this issue in TypeScript v5.7.3

⏯ Playground Link

https://www.typescriptlang.org/play/?ts=5.7.3#code/C4TwDgpgBAglC8UDeUBEBDVAuKA7ArgLYBGEATlAL5QA+U+uAJhAGYCWuEjA3AFC+hIsAApkA9pDKgEsKBAAewCEwDOyNJhwcW5KABUqUAPz6oOTgDdyfXgGMxuFcCjocMURPLTEARiA

πŸ’» Code

type A = { "a": number } | undefined;

type AProperty = A extends { "a": infer T } ? T : never;

const a: AProperty = 1

πŸ™ Actual behavior

TypeScript is returning AProperty as never.

Image

πŸ™‚ Expected behavior

I expected AProperty to resolve to number, as the type { "a": number } exists within the union type A.

Additional information about the issue

No response

@MartinJohns
Copy link
Contributor

MartinJohns commented Jan 23, 2025

This is working correctly. The type { a: number } | undefined does not extend the type { a: number }.

Note: Unless the type you check (A in this case) is a generic type you will not get distributive behavior. Perhaps you expected this?

@RyanCavanaugh RyanCavanaugh added the Working as Intended The behavior described is the intended behavior; this is not a bug label Jan 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

3 participants