-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Wrong function return type inference (union type parameter) #35106
Comments
Are you looking for generic functions? |
@AnyhowStep like so ?
indeed it seems to do the job, but I'm getting |
More like const unwrapTestObject = <T extends ITestOptional>({ key }: T): Pick<T, "key"> => ({ key }) The compiler is working as intended (the compiler doesn't distribute control flow analysis over union types); you might consider closing this issue. Good luck! |
That's a bit complicated but thanks it's working ! Because I simplified this for the example, but I have to do this with objects of 50 keys or more. So i need to put them all in the Sorry I opened a bug report for this. |
TypeScript Version: 3.8.0-dev.20191114
Search Terms: Wrong union type parameter function result type inference
Code
Expected behavior:
Output type should be inferred from input type even when using Union types (because it is specified in the parameter type).
Actual behavior:
Parameter type is totally ignored.
Playground Link
Related Issues:
Did not find anything similar.
The text was updated successfully, but these errors were encountered: