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

Generic function return value not fully inferred through generic argument #55553

Closed
m-dressler opened this issue Aug 28, 2023 · 2 comments
Closed
Labels
Duplicate An existing issue was already created

Comments

@m-dressler
Copy link

πŸ”Ž Search Terms

"typescript generic constraint return type", "typescript generic constraint return type error", "ts 2322", "typescript 2322 constraint return type"

πŸ•— Version & Regression Information

  • Tested on nightly & 5.1.6

⏯ Playground Link

https://www.typescriptlang.org/play?ts=5.3.0-dev.20230828#code/MYewdgzgLgBAhjAvDAPAFRgUwB5U2AEwhgCMQQAbTOMGAHxjAFcKKA+ACjgCcBzALhhoAlIIw48hYs1YwA-IyYBbEpm4xB0bgEswvJGxgBvAFAwY2gGYwufJImQyKwmN0xQm3WgAYA3Gdd3T1oAIhD-AF9fIA

πŸ’» Code

const a = <T extends boolean | null>(arg: T): T extends null ? number : string => {
  if (arg === null) return 0;
  return "";
};

πŸ™ 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

@MartinJohns
Copy link
Contributor

Duplicate of #33912.

@andrewbranch andrewbranch added the Duplicate An existing issue was already created label Aug 29, 2023
@typescript-bot
Copy link
Collaborator

This issue has been marked as "Duplicate" and has seen no recent activity. It has been automatically closed for house-keeping purposes.

@typescript-bot typescript-bot closed this as not planned Won't fix, can't repro, duplicate, stale Sep 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants