-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
DuplicateAn existing issue was already createdAn existing issue was already createdSuggestionAn idea for TypeScriptAn idea for TypeScript
Description
There is a type that is quite interesting in typescript void | {}
, this type has some unique behavior, everything can be assigned to this type, but the compiler does not infer any property for this type unlike for {}
that inherits the basic object properties, the difference with {}
is subtile but still pretty interesting:
function func1(val: {} ) {
val.hasOwnProperty('hello'); // no error
}
function func2(val: {} | void) {
val.hasOwnProperty('hello'); // error: Property 'hasOwnProperty' does not exist on type 'void | {}'.
}
However there is not typeguard for void
, it could be interesting to add some type guards for this case:
typeof val !== 'undefined'
val !== undefined
val != undefined
val != null
Metadata
Metadata
Assignees
Labels
DuplicateAn existing issue was already createdAn existing issue was already createdSuggestionAn idea for TypeScriptAn idea for TypeScript