-
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
Generic mapping returns union type #36349
Comments
TS would need some higher-order reasoning to be able to detect that this code is correct. The problem is that |
Isn't that enforced by type ResponseTransformerMapping = {
[Action in keyof Responses]: (data: any) => Responses[Action];
};
// ...
export const accessData = <Action extends keyof ResponseTransformerMapping>( // ... |
TypeScript Version: 3.8.0-dev.20200119
Search Terms:
generic map
generic function union
Code
Expected behavior:
Return type should be
Responses[Action]
Actual behavior:
Return type is
{ pong: number; } | { status: string; }
Using
return ResponseTransformers[action]({}) as Responses[Action];
works fine.Playground Link: link
Related Issues:
Maybe #33014
The text was updated successfully, but these errors were encountered: