Skip to content

nested keys are not inferred on queries #18

Description

@christophe-g

This works well:

const posts = yield* repo.query(Query.where('status', '==', 'published'));

However, this does not:

const posts = yield* repo.query(Query.where('metaData.type', '==', 'post'));

I use this type utils for inferring keys with dot notation, which I think can be useful here (instead of type FieldKeys<S> in query.ts):

type DotPrefix<T extends string> = T extends "" ? "" : `.${T}`
export type NestedFieldKeys<T> = (
  T extends object ?
  { [K in Exclude<keyof T, symbol>]: `${K}${DotPrefix<NestedFieldKeys<T[K]>>}` }[Exclude<keyof T, symbol>]
  : "") extends infer D ? Extract<D, string> : never;

type Form = {
  a: { b: string, c: number }
}

type FormKeys = NestedFieldKeys<Form>  // will be 'a.b' | 'a.c'

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions