We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
infer T in conditional type union returns never
I started encountering this issue in TypeScript v5.7.3
https://www.typescriptlang.org/play/?ts=5.7.3#code/C4TwDgpgBAglC8UDeUBEBDVAuKA7ArgLYBGEATlAL5QA+U+uAJhAGYCWuEjA3AFC+hIsAApkA9pDKgEsKBAAewCEwDOyNJhwcW5KABUqUAPz6oOTgDdyfXgGMxuFcCjocMURPLTEARiA
type A = { "a": number } | undefined; type AProperty = A extends { "a": infer T } ? T : never; const a: AProperty = 1
TypeScript is returning AProperty as never.
I expected AProperty to resolve to number, as the type { "a": number } exists within the union type A.
No response
The text was updated successfully, but these errors were encountered:
This is working correctly. The type { a: number } | undefined does not extend the type { a: number }.
{ a: number } | undefined
{ 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?
A
Sorry, something went wrong.
No branches or pull requests
π 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
π Actual behavior
TypeScript is returning AProperty as never.
π 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
The text was updated successfully, but these errors were encountered: