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
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:However there is not typeguard for
void, it could be interesting to add some type guards for this case:typeof val !== 'undefined'val !== undefinedval != undefinedval != null