Type alias NestedPaths<Type, Depth>

NestedPaths<Type, Depth>: Depth["length"] extends 8
    ? []
    : Type extends string | number | bigint | boolean | Date | RegExp | Buffer | Uint8Array | ((...args) => any) | {
            _bsontype: string;
        }
        ? []
        : Type extends ReadonlyArray<infer ArrayType>
            ? [] | [number, ...NestedPaths<ArrayType, [...Depth, 1]>]
            : Type extends Map<string, any>
                ? [string]
                : Type extends object
                    ? {
                        [Key in Extract<keyof Type, string>]: Type[Key] extends Type
                            ? [Key]
                            : Type extends Type[Key]
                                ? [Key]
                                : Type[Key] extends ReadonlyArray<infer ArrayType>
                                    ? Type extends ArrayType
                                        ? [Key]
                                        : ArrayType extends Type
                                            ? [Key]
                                            : [Key, ...NestedPaths<Type[Key], [...Depth, 1]>]
                                    : [Key, ...NestedPaths<Type[Key], [...Depth, 1]>] | [Key]
                    }[Extract<keyof Type, string>]
                    : []

returns tuple of strings (keys to be joined on '.') that represent every path into a schema https://www.mongodb.com/docs/manual/tutorial/query-embedded-documents/

Type Parameters

  • Type

  • Depth extends number[]

Remarks

Through testing we determined that a depth of 8 is safe for the typescript compiler and provides reasonable compilation times. This number is otherwise not special and should be changed if issues are found with this level of checking. Beyond this depth any helpers that make use of NestedPaths should devolve to not asserting any type safety on the input.

Generated using TypeDoc