UNPKG

758 BTypeScriptView Raw
1/**
2 * This utility type forms an object type of `Options` by taking values from
3 * `OverrideOptions`. If a value is not defined in `OverrideOptions`, the
4 * utility type takes the value from `DefaultOptions`.
5 *
6 * The utility type intentionally restricts:
7 * - `Options` to be required to know the object type form.
8 * - `OverrideOptions` to be partial to make empty object assignable to it.
9 * - `DefaultOptions` to be required to have fallback values for every property.
10 */
11export type CreateTypeOptions<
12 Options extends Required<Options>,
13 OverrideOptions extends Partial<Options>,
14 DefaultOptions extends Required<Options>,
15> = {
16 [Key in keyof Options]: OverrideOptions[Key] extends Options[Key] ? OverrideOptions[Key] : DefaultOptions[Key];
17};