table icon indicating copy to clipboard operation
table copied to clipboard

Fix DeepKeys to handle arrays properly

Open mimbrown opened this issue 7 months ago • 0 comments

The types for nested arrays in the DeepKeys type seem definitely wrong to me. The type properly handles tuples, but not arrays of arbitrary length. For example, given this type:

DeepKeys<{
  foo: { bar: string }[];
}>

This currently resolves to "foo" | "foo.bar", which is unexpected. If we change the type to be a tuple (i.e. { bar: string }[] --> [{ bar: string }]), then we correctly get "foo" | "foo.0.bar".

This change updates the handling for arbitrary length arrays so that the above type will resolve to:

"foo" | `foo.${number}` | `foo.${number}.bar`

This puts the onus on the user to make sure the number is not out of range, but that seems reasonable to me.

mimbrown avatar Jun 02 '25 17:06 mimbrown