UNPKG

svelte-hook-form

Version:
39 lines (38 loc) 1.58 kB
export declare type Primitive = null | undefined | string | number | boolean | symbol | bigint | Date; export declare type IsArray<T> = T extends ReadonlyArray<any> ? true : false; /** * Type which given a tuple type returns its own keys, i.e. only its indices. * @typeParam T - tuple type * @example * ``` * TupleKeys<[number, string]> = '0' | '1' * ``` */ export declare type TupleKeys<T extends ReadonlyArray<any>> = Exclude<keyof T, keyof any[]>; /** * Type to query whether an array type T is a tuple type. * @typeParam T - type which may be an array or tuple * @example * ``` * IsTuple<[number]> = true * IsTuple<number[]> = false * ``` */ export declare type IsTuple<T extends ReadonlyArray<any>> = number extends T["length"] ? false : true; /** * Helper type for recursively constructing paths through a type. * See {@link Path} */ declare type PathImpl<K extends string | number, V> = V extends Primitive ? `${K}` : V extends ReadonlyArray<infer KV> ? `${K}` | `${K}${ArrayPathImpl<KV>}` : `${K}` | `${K}.${Path<V>}`; declare type ArrayPathImpl<V extends any> = V extends Primitive ? `[${number}]` : `[${number}]` | `[${number}].${Path<V>}`; export declare type Path<T> = T extends ReadonlyArray<infer V> ? IsTuple<T> extends true ? { [K in TupleKeys<T>]-?: PathImpl<K & string, T[K]>; }[TupleKeys<T>] : ArrayPathImpl<V> : { [K in keyof T]-?: PathImpl<K & string, T[K]>; }[keyof T]; export declare type FieldValues<T = any> = Record<string, T>; /** * See {@link Path} */ export declare type FieldPath<T extends FieldValues> = Path<T>; export {};