cal/packages/types/utils.d.ts

18 lines
634 B
TypeScript
Raw Normal View History

2022-01-19 13:24:01 -03:00
/** Makes selected props from a record non optional */
export type Ensure<T, K extends keyof T> = Omit<T, K> & {
[EK in K]-?: NonNullable<T[EK]>;
};
2022-01-19 13:24:01 -03:00
/** Makes selected props from a record optional */
export type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>;
/** Get the union type of all the values in an object, array or array-like type `T` */
export type ValuesType<T extends ReadonlyArray<unknown> | ArrayLike<unknown> | Record<unknown, unknown>> =
T extends ReadonlyArray<unknown>
? T[number]
: T extends ArrayLike<unknown>
? T[number]
: T extends object
? T[keyof T]
: never;