- property<T, K>(key, obj): Maybe<NonNullable<T[K]>>
Type Parameters
- T
- K extends string | number | symbol
Returns Maybe<NonNullable<T[K]>>
- property<T, K>(key): ((obj: T) => Maybe<NonNullable<T[K]>>)
Type Parameters
- T
- K extends string | number | symbol
Returns ((obj: T) => Maybe<NonNullable<T[K]>>)
Safely extract a key from an object, returning
Just
if the key has a value on the object andNothing
if it does not.The check is type-safe: you won't even be able to compile if you try to look up a property that TypeScript knows doesn't exist on the object.
However, it also works correctly with dictionary types:
The order of keys is so that it can be partially applied: