Switch exhaustiveness not working for typeof any
and typeof unknown
#39343
Labels
Bug
A bug in TypeScript
Effort: Moderate
Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual".
Help Wanted
You can do this
Milestone
TypeScript Version: 3.9.5, 4.0.0-dev.20200630
Search Terms: switch narrowing typeof any unknown
Code
Making
x
unknown
also gives the same results.Expected behavior: No error in
doesntWork
as the switch is exhaustive. This should be the same asworks
(using a variable) andalsoWorks
(using a type assertion).Actual behavior: Error
TS 2366: Function lacks ending return statement and return type does not include 'undefined'.
withstrictNullChecks
.Playground Link
Related Issues: #34661, #38136, #27180
The text was updated successfully, but these errors were encountered: