Skip to content

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

Open
@DanielRosenwasser

Description

@DanielRosenwasser
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.

Activity

fatcerberus

fatcerberus commented on Mar 28, 2023

@fatcerberus

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

DanielRosenwasser

DanielRosenwasser commented on Mar 28, 2023

@DanielRosenwasser
MemberAuthor

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.

added
RescheduledThis issue was previously scheduled to an earlier milestone
on Mar 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugA bug in TypeScriptDomain: Error MessagesThe issue relates to error messagingFix AvailableA PR has been opened for this issueRescheduledThis issue was previously scheduled to an earlier milestone

Type

No type

Projects

No projects

Relationships

None yet

    Participants

    @DanielRosenwasser@fatcerberus@RyanCavanaugh@typescript-bot

    Issue actions

      Error for explicit return type with no return statements is misleading · Issue #53559 · microsoft/TypeScript