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
"typescript generic constraint return type", "typescript generic constraint return type error", "ts 2322", "typescript 2322 constraint return type"
https://www.typescriptlang.org/play?ts=5.3.0-dev.20230828#code/MYewdgzgLgBAhjAvDAPAFRgUwB5U2AEwhgCMQQAbTOMGAHxjAFcKKA+ACjgCcBzALhhoAlIIw48hYs1YwA-IyYBbEpm4xB0bgEswvJGxgBvAFAwY2gGYwufJImQyKwmN0xQm3WgAYA3Gdd3T1oAIhD-AF9fIA
const a = <T extends boolean | null>(arg: T): T extends null ? number : string => { if (arg === null) return 0; return ""; };
Caused a typescript error Type 'number' is not assignable to type 'T extends null ? number : string'.(2322)
Type 'number' is not assignable to type 'T extends null ? number : string'.(2322)
No error as argument is used to check type of generic T and returns correct return type for function.
T
No response
The text was updated successfully, but these errors were encountered:
Duplicate of #33912.
Sorry, something went wrong.
This issue has been marked as "Duplicate" and has seen no recent activity. It has been automatically closed for house-keeping purposes.
No branches or pull requests
π Search Terms
"typescript generic constraint return type", "typescript generic constraint return type error", "ts 2322", "typescript 2322 constraint return type"
π Version & Regression Information
β― Playground Link
https://www.typescriptlang.org/play?ts=5.3.0-dev.20230828#code/MYewdgzgLgBAhjAvDAPAFRgUwB5U2AEwhgCMQQAbTOMGAHxjAFcKKA+ACjgCcBzALhhoAlIIw48hYs1YwA-IyYBbEpm4xB0bgEswvJGxgBvAFAwY2gGYwufJImQyKwmN0xQm3WgAYA3Gdd3T1oAIhD-AF9fIA
π» Code
π Actual behavior
Caused a typescript error
Type 'number' is not assignable to type 'T extends null ? number : string'.(2322)
π Expected behavior
No error as argument is used to check type of generic
T
and returns correct return type for function.Additional information about the issue
No response
The text was updated successfully, but these errors were encountered: