We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Return type of a function gets incorrectly inferred when nesting a case in an if.
I have reproduced this with typescript@next (3.5.0-dev.20190529)
typescript@next
3.5.0-dev.20190529
Search Terms: switch + return type switch + noImplicitReturns
Code
with the compiler option noImplicitReturns:
noImplicitReturns
export type Q = { type: "A" } | { type: "B" }; export function f1(q: Q | undefined): string { if (q) { switch (q.type) { case "A": return "A"; case "B": return "B"; } } else { return "nothing"; } } export function f2(q: Q | undefined): string { if (q) { return f2_help(q); } else { return "nothing"; } } function f2_help(q: Q): string { switch (q.type) { case "A": return "A"; case "B": return "B"; } }
Expected behavior:
I'd expect both f1 and f2 to compile, since I can get f1 by inlining f2_help into f2.
f1
f2
f2_help
Actual behavior:
But f1 gives me an error:
Error:
testcase.ts:3:39 - error TS7030: Not all code paths return a value. 3 export function f1(q: Q | undefined): string { ~~~~~~ Found 1 error.
Playground Link:
NOTE: this only fails with noImplicitReturns turned on in the option (the option does not get saved in the url)
Playground
Repository reproducing the issue
https://github.com/archaeron/typescript-testcase
Related Issues:
Might be related: #31495
The text was updated successfully, but these errors were encountered:
Duplicate #11572
Sorry, something went wrong.
This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.
No branches or pull requests
Return type of a function gets incorrectly inferred when nesting a case in an if.
I have reproduced this with
typescript@next
(3.5.0-dev.20190529
)Search Terms:
switch + return type
switch + noImplicitReturns
Code
with the compiler option
noImplicitReturns
:Expected behavior:
I'd expect both
f1
andf2
to compile, since I can getf1
by inliningf2_help
intof2
.Actual behavior:
But
f1
gives me an error:Error:
Playground Link:
NOTE: this only fails with
noImplicitReturns
turned on in the option (the option does not get saved in the url)Playground
Repository reproducing the issue
https://github.com/archaeron/typescript-testcase
Related Issues:
Might be related: #31495
The text was updated successfully, but these errors were encountered: