Skip to content

nested keys are not inferred on queries #18

@christophe-g

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'

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