Skip to content

Fix DeepKeys to handle arrays properly #6031

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mimbrown
Copy link

@mimbrown mimbrown commented Jun 2, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant