-
-
Notifications
You must be signed in to change notification settings - Fork 662
Open
Labels
Description
Type description + examples
Determine if a possibly nullish object contains a property.
It could be paired with something like this:
const hasOwnNonNullish = <T extends object, K extends keyof T>(
object: T | null | undefined | void,
property: K
): object is NonNullishProp<T, K> =>
object != null &&
Object.prototype.hasOwnProperty.call(object, property) &&
(object as any)[property] != null;Type source
export type NonNullishProp<T, K extends keyof T> = T & {
[P in K]-?: Exclude<T[P], null | undefined | void>;
};Search existing types and issues first
- I tried my best to look for it