Type Alias NestedPaths<Type, Depth>

NestedPaths<Type, Depth>: Depth["length"] extends 8
    ? []
    : Type extends
            | string
            | number
            | bigint
            | boolean
            | Date
            | RegExp
            | Buffer
            | Uint8Array
            | ((...args: any[]) => 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]
                                : (...)[(...)] extends ReadonlyArray<(...)>
                                    ? (...) extends (...)
                                        ? (...)
                                        : (...)
                                    : (...) | (...)
                    }[Extract<keyof Type, string>]
                    : []

returns tuple of strings (keys to be joined on '.') that represent every path into a schema /v8.3/tutorial/query-embedded-documents/

Type Parameters

  • Type
  • Depth extends number[]

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.通过测试,我们确定深度为8对typescript编译器是安全的,并提供了合理的编译时间。此数字在其他方面并不特殊,如果发现此级别的检查存在问题,则应更改。超过这个深度,任何使用NestedPaths的助手都应该降级为不对输入断言任何类型安全。