import type { Head, Tail } from "./tuple.js"; /** * A version of `T` in which only keys in K are mandatory and the rest are * considered optional. */ export type SomeRequired = Partial> & Required>; /** * Extracts from A all keys which have values assignable to type B. */ export type TypedKeys = { [P in Keys]: B extends A[P] ? P : never; }[keyof A]; export type NumericKeys = TypedKeys; export type StringKeys = TypedKeys; export type DeepPartial = Partial<{ [k in keyof T]: DeepPartial; }>; export type Keys = keyof Required; export type Keys1> = Keys[A]>; export type Keys2, B extends Keys1> = Keys1[A], B>; export type Keys3, B extends Keys1, C extends Keys2> = Keys2[A], B, C>; export type Keys4, B extends Keys1, C extends Keys2, D extends Keys3> = Keys3[A], B, C, D>; export type Keys5, B extends Keys1, C extends Keys2, D extends Keys3, E extends Keys4> = Keys4[A], B, C, D, E>; export type Keys6, B extends Keys1, C extends Keys2, D extends Keys3, E extends Keys4, F extends Keys5> = Keys5[A], B, C, D, E, F>; export type Keys7, B extends Keys1, C extends Keys2, D extends Keys3, E extends Keys4, F extends Keys5, G extends Keys6> = Keys6[A], B, C, D, E, F, G>; export type Keys8, B extends Keys1, C extends Keys2, D extends Keys3, E extends Keys4, F extends Keys5, G extends Keys6, H extends Keys7> = Keys7[A], B, C, D, E, F, G, H>; /** * Internal type used as a reducer for the KeyN type. * * @internal * * @param T - structure to validate the key against. * @param L - Current value. * @param R - Remaining values. */ type KeysNReducer = L extends keyof T ? { 0: keyof Required[L]; 1: KeysNReducer[L], Head, Tail>; }[R extends [] ? 0 : 1] : never; /** * Generalised version of Keys0 - Keys7. */ export type KeysN = L extends [] ? Keys : KeysNReducer, Tail>; export type Val1> = T[A]; export type Val2, B extends Keys1> = ValN; export type Val3, B extends Keys1, C extends Keys2> = ValN; export type Val4, B extends Keys1, C extends Keys2, D extends Keys3> = ValN; export type Val5, B extends Keys1, C extends Keys2, D extends Keys3, E extends Keys4> = ValN; export type Val6, B extends Keys1, C extends Keys2, D extends Keys3, E extends Keys4, F extends Keys5> = ValN; export type Val7, B extends Keys1, C extends Keys2, D extends Keys3, E extends Keys4, F extends Keys5, G extends Keys6> = ValN; export type Val8, B extends Keys1, C extends Keys2, D extends Keys3, E extends Keys4, F extends Keys5, G extends Keys6, H extends Keys7> = ValN; /** * Internal reducer for ValN. * * @internal * * @param T - he structure to get the values from. * @param C - he current key. * @param R - he remaining keys */ type ValNReducer = C extends keyof T ? { 0: T[C]; 1: ValNReducer[C], Head, Tail>; }[R extends [] ? 0 : 1] : never; /** * Generalised version of Val1-Val7 */ export type ValN = L extends [] ? T : ValNReducer, Tail>; /** * Utilities for constructing types with nested keys removed. */ export type Without> = Omit; export type Without2, B extends Keys1> = Without & { [id in A]: Without, B>; }; export type Without3, B extends Keys1, C extends Keys2> = Without & { [id in A]: Without2, B, C>; }; export type Without4, B extends Keys1, C extends Keys2, D extends Keys3> = Without & { [id in A]: Without3, B, C, D>; }; export type Without5, B extends Keys1, C extends Keys2, D extends Keys3, E extends Keys4> = Without & { [id in A]: Without4, B, C, D, E>; }; export type Without6, B extends Keys1, C extends Keys2, D extends Keys3, E extends Keys4, F extends Keys5> = Without & { [id in A]: Without5, B, C, D, E, F>; }; export type Without7, B extends Keys1, C extends Keys2, D extends Keys3, E extends Keys4, F extends Keys5, G extends Keys6> = Without & { [id in A]: Without6, B, C, D, E, F, G>; }; export type Without8, B extends Keys1, C extends Keys2, D extends Keys3, E extends Keys4, F extends Keys5, G extends Keys6, H extends Keys7> = Without & { [id in A]: Without7, B, C, D, E, F, G, H>; }; /** * Internal reducer used as a building block for WithoutN. * * @internal * * @param T - he structure to remove keys from. * @param C - he current key. * @param R - he remaining keys. */ type WithoutNReducer = C extends keyof T ? { 0: Without; 1: Without & Record, Tail>>; }[R extends [] ? 0 : 1] : never; /** * Generalised version of Without0-Without8. */ export type WithoutN = WithoutNReducer, Tail

>; /** * Utilities for replacing types of nested keys. */ export type Replace, V> = Without & { [id in A]: V; }; export type Replace2, B extends Keys1, V> = Without & { [id in A]: Replace, B, V>; }; export type Replace3, B extends Keys1, C extends Keys2, V> = Without & { [id in A]: Replace2, B, C, V>; }; export type Replace4, B extends Keys1, C extends Keys2, D extends Keys3, V> = Without & { [id in A]: Replace3, B, C, D, V>; }; export type Replace5, B extends Keys1, C extends Keys2, D extends Keys3, E extends Keys4, V> = Without & { [id in A]: Replace4, B, C, D, E, V>; }; export type Replace6, B extends Keys1, C extends Keys2, D extends Keys3, E extends Keys4, F extends Keys5, V> = Without & { [id in A]: Replace5, B, C, D, E, F, V>; }; export type Replace7, B extends Keys1, C extends Keys2, D extends Keys3, E extends Keys4, F extends Keys5, G extends Keys6, V> = Without & { [id in A]: Replace6, B, C, D, E, F, G, V>; }; export type Replace8, B extends Keys1, C extends Keys2, D extends Keys3, E extends Keys4, F extends Keys5, G extends Keys6, H extends Keys7, V> = Without & { [id in A]: Replace7, B, C, D, E, F, G, H, V>; }; /** * Internal reducer used as a building block for ReduceN. * * @internal * * @param T - he structure to remove keys from. * @param C - he current key. * @param R - he remaining keys. * @param V - he type to use for the replacement. */ type ReplaceNReducer = C extends keyof T ? { 0: Replace; 1: Without & Record, Tail, V>>; }[R extends [] ? 0 : 1] : never; /** * Generalised version of Replace0-Replace8. */ export type ReplaceN = ReplaceNReducer, Tail

, V>; export {}; //# sourceMappingURL=keyval.d.ts.map