diff --git a/source/get.d.ts b/source/get.d.ts index 9b56fef78..06e5726aa 100644 --- a/source/get.d.ts +++ b/source/get.d.ts @@ -17,7 +17,7 @@ type GetOptions = { Like the `Get` type but receives an array of strings as a path parameter. */ type GetWithPath = - Keys extends [] + Keys extends readonly [] ? BaseType : Keys extends readonly [infer Head, ...infer Tail] ? GetWithPath< @@ -125,7 +125,7 @@ type PropertyOf = ? undefined : Key extends keyof BaseType ? StrictPropertyOf - : BaseType extends [] | [unknown, ...unknown[]] + : BaseType extends readonly [] | readonly [unknown, ...unknown[]] ? unknown // It's a tuple, but `Key` did not extend `keyof BaseType`. So the index is out of bounds. : BaseType extends { [n: number]: infer Item; diff --git a/test-d/get.ts b/test-d/get.ts index 3499d8e79..2d62f1720 100644 --- a/test-d/get.ts +++ b/test-d/get.ts @@ -132,3 +132,11 @@ expectTypeOf>().toEqualTypeOf<{bar: number} expectTypeOf>().toEqualTypeOf(); expectTypeOf>().toEqualTypeOf(); expectTypeOf>().toEqualTypeOf(); + +// Test array index out of bounds +expectTypeOf>().toEqualTypeOf(); +expectTypeOf>().toEqualTypeOf(); + +// Test empty path array +expectTypeOf().toEqualTypeOf>(); +expectTypeOf().toEqualTypeOf>();