Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to dynamically type terms in createIndex #1

Open
taylor-lindores-reeves opened this issue Oct 5, 2023 · 1 comment
Open

Comments

@taylor-lindores-reeves
Copy link

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;

@chronark
Copy link
Contributor

chronark commented Oct 6, 2023

We should probably export it
a quick way to do it would be this:

type Terms = Parameters<typeof authstore.createIndex>[0]["terms"]

CleanShot 2023-10-06 at 09 36 45

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants