Skip to content

fix(43160): improve error location for functions without explicit return #43367

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

Merged
merged 2 commits into from
Apr 6, 2021

Conversation

Zzzen
Copy link
Contributor

@Zzzen Zzzen commented Mar 25, 2021

Fixes #43160

@typescript-bot typescript-bot added the For Backlog Bug PRs that fix a backlog bug label Mar 25, 2021
Copy link
Member

@sandersn sandersn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice improvement. One request to make the function even easier to read.

// NOTE: having returnType !== undefined is a precondition for entering this branch so func.type will always be present
error(getEffectiveReturnTypeNode(func), Diagnostics.A_function_whose_declared_type_is_neither_void_nor_any_must_return_a_value);
// NOTE: returnType may not exist when func.type is denoted by jsdoc
error(getEffectiveReturnTypeNode(func) || func, Diagnostics.A_function_whose_declared_type_is_neither_void_nor_any_must_return_a_value);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all 4 four branches of this if at the end of the function now have getEffectiveReturnTypeNode(func) || func, so I'd lift it out before the first if as const errorNode = getEffectiveReturnTypeNode(func) || func

If you can, you should find or write a new test for the type.flags & TypeFlags.Never case above as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌 👌 Got it.

@sandersn sandersn merged commit 3cf26e4 into microsoft:master Apr 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Backlog Bug PRs that fix a backlog bug
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

JS typings, missing file reference for error TS2355 when tyiping functions with @type
3 participants