TypeScript Version: master 83fe1ea
Search Terms: switch typeof unknown
Code
// @strictNullChecks: true
function unknownNarrowing(x: unknown) {
switch (typeof x) {
case 'function': x; return; // x is unknown, should be Function
case 'object': x; return; // x is unknown, should be object | null
}
}
Expected behavior:
- Narrowing
unknown in switch at clause "function" should result in type Function.
- Narrowing
unknown in switch at clause "object" should result in type object | null.
Actual behavior:
- Value of type
unknown does not narrow.
Playground Link: N/A (Playground not on this version).
TypeScript Version: master 83fe1ea
Search Terms: switch typeof unknown
Code
Expected behavior:
unknownin switch at clause"function"should result in typeFunction.unknownin switch at clause"object"should result in typeobject | null.Actual behavior:
unknowndoes not narrow.Playground Link: N/A (Playground not on this version).