-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
typescript always return a intersection even though I specify the generic #47749
Comments
yep, that makes sense , ty |
I don't believe that #27808 covers your issue. #27808 is concerned with presenting the correct calling interface that rejects illegal calls. In your code that is already miraculously working -
Your description of expected and actual behavior is a bit confusing to me. I see the actual behavior to be that TS shows It also actually complains that
When strictly checked it requires all four properties:
It is just lucky circumstance (or careful planning) that it doesn't fail in If the type-checker went through case of allowed parameter list types and performed a separate type-check for each one, then your error would not occur. The are good reasons for not doing that always - it takes more time.
and two known invalid cases
so it would just type-check to two valid cases. |
Bug Report
I trying to create a function that will return a different instance of class by passing different args ,
but when I specify the generic of args, typescript always return an intersection instead of union;
🔎 Search Terms
generic
🕗 Version & Regression Information
typescript: 4.3.5
Same behavior in 4.5.4
⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
args
return an intersection ( ClassAOptions & ClassBOptions )🙂 Expected behavior
args
should be an Union ( ClassAOptions | ClassBOptions )The text was updated successfully, but these errors were encountered: