Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

Merged
sandersn merged 2 commits into
microsoft:mastermicrosoft/TypeScript:masterfrom
Zzzen:gh-43160Zzzen/TypeScript:gh-43160Copy head branch name to clipboard
Apr 6, 2021
Merged

fix(43160): improve error location for functions without explicit return#43367
sandersn merged 2 commits into
microsoft:mastermicrosoft/TypeScript:masterfrom
Zzzen:gh-43160Zzzen/TypeScript:gh-43160Copy head branch name to clipboard

Conversation

@Zzzen

@Zzzen Zzzen commented Mar 25, 2021

Copy link
Copy Markdown
Contributor

Fixes #43160

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

@sandersn sandersn left a comment

Copy link
Copy Markdown
Member

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.

Comment thread src/compiler/checker.ts Outdated
// 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
Copy Markdown
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
Copy Markdown
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
@microsoft microsoft locked as resolved and limited conversation to collaborators Oct 21, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

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

Morty Proxy This is a proxified and sanitized view of the page, visit original site.