Skip to content

TS2366: Function lacks ending return statement in function with unknown return type with implicit return on some code paths, despite noImplicitReturns turned offΒ #53473

@AlCalzone

Description

@AlCalzone

Bug Report

πŸ”Ž Search Terms

lacks ending

πŸ•— Version & Regression Information

  • This changed between versions 5.0.2 and 5.1.0-dev.20230323

I believe this caused it.

⏯ Playground Link

https://www.typescriptlang.org/play?noImplicitReturns=false&ts=5.1.0-dev.20230323#code/GYVwdgxgLglg9mABFApgZygCgJQC5HgDWYcA7kgN4CwAUAJAzCKYCyAhlABYB0ATm2AAmcALY5EAPkQAGbgFZsiXiigheSKLxAoA3LQC+QA

πŸ’» Code

function test(): unknown {
	if (Math.random() > 0.5) return true;
}

πŸ™ Actual behavior

> tsc --noEmit

index.ts:1:18 - error TS2366: Function lacks ending return statement and return type does not include 'undefined'.

1 function test(): unknown {
                   ~~~~~~~

πŸ™‚ Expected behavior

No error, if the function return type is unknown I'd expect that to allow implicit return of undefined.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issueGood First IssueWell scoped, documented and has the green lightHelp WantedYou can do this

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions