-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Type inference issue with overload signatures and string literal types #15086
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
Comments
This is working correctly since the overloads only differ by the type of one argument but have the same return type. You should rather write export function test(key: "aa"): A;
export function test(key: "bb2" | "bb1"): B;
export function test(key: string): Base {
return { key: key };
} See here https://www.typescriptlang.org/docs/handbook/declaration-files/do-s-and-don-ts.html for more information (end of page) |
I'm sorry @aluanhaddad, but no, it's not working correctly. E.g.
Typescript has all the information at compile time to understand that calling test() with an argument of type "bb1" | "bb2" will surely produce a return of type B, so it's definitely an issue that it's not working right now. Thanks |
Duplicate of #14107 |
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed. |
TypeScript Version: 2.2.1 / nightly (2.2.0-dev.201xxxxx)
Code
playground url:
here
Expected behavior:
No compiler errors; type inference to understand that "return test(key)" returns a B type.
Actual behavior:
"return test(key)" doesn't compile because of an argument type error
The text was updated successfully, but these errors were encountered: