Skip to content
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

Error for explicit return type with no return statements is misleading #53559

Open
DanielRosenwasser opened this issue Mar 28, 2023 · 2 comments · May be fixed by #53560
Open

Error for explicit return type with no return statements is misleading #53559

DanielRosenwasser opened this issue Mar 28, 2023 · 2 comments · May be fixed by #53560
Assignees
Labels
Bug A bug in TypeScript Domain: Error Messages The issue relates to error messaging Fix Available A PR has been opened for this issue Rescheduled This issue was previously scheduled to an earlier milestone

Comments

@DanielRosenwasser
Copy link
Member

DanielRosenwasser commented Mar 28, 2023

function foo(): string {
}

Currently in nightly, you'll get the error

error TS2847: A function whose declared type is neither 'undefined', 'void', nor 'any' must return a value.

But this error message is inaccurate, as you can now annotate with unknown.

@DanielRosenwasser DanielRosenwasser added Bug A bug in TypeScript Domain: Error Messages The issue relates to error messaging labels Mar 28, 2023
@DanielRosenwasser DanielRosenwasser added this to the TypeScript 5.1.0 milestone Mar 28, 2023
@DanielRosenwasser DanielRosenwasser self-assigned this Mar 28, 2023
@typescript-bot typescript-bot added the Fix Available A PR has been opened for this issue label Mar 28, 2023
@fatcerberus
Copy link

In fact can't you now annotate with any type which is inhabited by undefined?

@DanielRosenwasser
Copy link
Member Author

Pretty much, which means that if you wrote

function foo(): string | undefined {
    // oops, forgot to fill this in
}

that'll be okay in TypeScript 5.1. You'll need to enable --noImplicitReturns to catch something like that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Domain: Error Messages The issue relates to error messaging Fix Available A PR has been opened for this issue Rescheduled This issue was previously scheduled to an earlier milestone
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants