-
-
Notifications
You must be signed in to change notification settings - Fork 662
Open
Labels
Description
Type description + examples
Partial allows for all properties to be undefined. This type would do that, but also accept null.
export type Nullish<T> = { [K in keyof T]?: T[K] | null }You may think "why not name it Nullable?" IMO, This would indicate only null, not also undefined. "Nullish" comes from the nullish coalescing operator ??-- "nullish" means "null or undefined"
Other possible names:
NullablePartial(butNullishis shorter and explains it)Nilable("nil" can also commonly mean "both nul and undefined")
I also think that with this, it would make sense to add:
IsNullish(orisNilable, if we go with that naming convention) - likeIsOptionalorIsNullable, but for both-- Returns a boolean for whether the given type includes null or undefined)NullishKeysOf/NilableKeysOf
Type source
No response
Search existing types and issues first
- I tried my best to look for it