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
function doSomething(value: unknown): object {
if (value !== null && typeof value === 'object'){
return value //value: object | null
}
if (typeof value === 'object' && value !== null){
return value //value: object
}
return {}
}
Expected behavior:
The variable "value" is correctly narrowed down to object in both cases
Actual behavior:
The variable is narrowed down to "object | null" in the first case and to only "object" in the second case.
TypeScript Version: 3.5.3, 3.9.2, 4.0.0-beta
Search Terms: type guard, incorrect type
Code
Expected behavior:
The variable "value" is correctly narrowed down to object in both cases
Actual behavior:
The variable is narrowed down to "object | null" in the first case and to only "object" in the second case.
Playground Link: test on playground
The text was updated successfully, but these errors were encountered: