diff --git a/source/paths.d.ts b/source/paths.d.ts index 07f5eab9b..f2aa78d00 100644 --- a/source/paths.d.ts +++ b/source/paths.d.ts @@ -1,4 +1,4 @@ -import type {StaticPartOfArray, VariablePartOfArray, NonRecursiveType, ToString, IsNumberLike, ApplyDefaultOptions} from './internal/index.d.ts'; +import type {NonRecursiveType, ToString, IsNumberLike, ApplyDefaultOptions} from './internal/index.d.ts'; import type {IsAny} from './is-any.d.ts'; import type {UnknownArray} from './unknown-array.d.ts'; import type {GreaterThan} from './greater-than.d.ts'; @@ -196,14 +196,9 @@ type _Paths, CurrentDepth extends numb ? never : IsAny extends true ? never - : T extends UnknownArray - ? number extends T['length'] - // We need to handle the fixed and non-fixed index part of the array separately. - ? InternalPaths, Options, CurrentDepth> | InternalPaths[number]>, Options, CurrentDepth> - : InternalPaths - : T extends object - ? InternalPaths - : never; + : T extends object + ? InternalPaths + : never; type InternalPaths, CurrentDepth extends number> = Options['maxRecursionDepth'] extends infer MaxDepth extends number diff --git a/test-d/paths.ts b/test-d/paths.ts index 464363d37..a612f167a 100644 --- a/test-d/paths.ts +++ b/test-d/paths.ts @@ -92,6 +92,12 @@ expectType(trailingSpreadTuple); declare const trailingSpreadTuple1: Paths<[{a: string}, {b: number}, ...Array<{c: number}>]>; expectType(trailingSpreadTuple1); +declare const optionalElementsWithTrailingSpreadTuple: Paths<{foo: [{a: string}, ({b: number})?, ...Array<{c: number}>]}>; +expectType<'foo' | `foo.${number}` | 'foo.0.a' | 'foo.1.b' | `foo.${number}.c`>(optionalElementsWithTrailingSpreadTuple); + +declare const optionalElementsWithTrailingSpreadTuple1: Paths<[({a: string})?, ({b: number})?, ...Array<{c: number}>]>; +expectType(optionalElementsWithTrailingSpreadTuple1); + declare const leadingSpreadTuple: Paths<[...Array<{a: string}>, {b: number}]>; expectType(leadingSpreadTuple);