You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
TS2366: Function lacks ending return statement in function with unknown return type with implicit return on some code paths, despite noImplicitReturns turned offΒ #53473
> 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.
changed the title [-]TS2366: Function lacks ending return statement in function with `unknown` return type with implicit return on some code paths[/-][+]TS2366: Function lacks ending return statement in function with `unknown` return type with implicit return on some code paths, despite `noImplicitReturns` turned off[/+]on Mar 23, 2023
Activity
fatcerberus commentedon Mar 23, 2023
The error message changed, but this is an error in 5.0.2 and earlier too:
AlCalzone commentedon Mar 23, 2023
Uh, the playground link had
noImplicitReturnsturned on. If you turn it off, it only becomes an error after 5.0.2. I'll update the link[-]TS2366: Function lacks ending return statement in function with `unknown` return type with implicit return on some code paths[/-][+]TS2366: Function lacks ending return statement in function with `unknown` return type with implicit return on some code paths, despite `noImplicitReturns` turned off[/+]fatcerberus commentedon Mar 23, 2023
What do you know, this actually broke some real-world code already. π
#53474 (comment)
AlCalzone commentedon Mar 23, 2023
Believe it or not, I found this in real-world code :D
DanielRosenwasser commentedon Mar 23, 2023
I think the simplest fix would just be to check for
TypeFlags.Unknown- alternatively, we restore theisTypeAssignableTo(undefinedType, type)check.Let's make sure that we test
strictNullCheckson/off with other top-y types.