query icon indicating copy to clipboard operation
query copied to clipboard

Ability to dynamically type terms in createIndex

Open taylor-lindores-reeves opened this issue 2 years ago • 1 comments

I want to be able to create a function that dynamically types indexes, however currently I am unable to type terms:

Screenshot 2023-10-05 at 14 02 18

When I hover over terms I get the following type constraint:

Type 'keyof T extends Data ? T : Data[]' is not assignable to type 'Join<NestedPaths<T extends Data ? T : Data>>[]'.

I noticed you are not exporting the Join / NestedPaths types. Is there a better way of achieving this? Am I missing something?

type NestedPaths<T> = T extends string | number | boolean ? [] : {
    [K in Extract<keyof T, string>]: [K, ...NestedPaths<T[K]>];
}[Extract<keyof T, string>];

type Join<T> = T extends [] ? never : T extends [infer F] ? F : T extends [infer F, ...infer R] ? F extends string ? ${F}.${Join<Extract<R, string[]>>} : never : string;

taylor-lindores-reeves avatar Oct 05 '23 13:10 taylor-lindores-reeves