query
query copied to clipboard
Ability to dynamically type terms in createIndex
I want to be able to create a function that dynamically types indexes, however currently I am unable to type terms:
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;
We should probably export it a quick way to do it would be this:
type Terms = Parameters<typeof authstore.createIndex>[0]["terms"]