Skip to content

fix[ObjectKeys]: keep string enum keys as the enum type - #2156

Merged
dayongkr merged 3 commits into
mainfrom
fix/object-keys-enum
Oct 23, 2026
Merged

dayongkr merged 3 commits into
mainfrom
fix/object-keys-enum

Conversation

@dayongkr

@dayongkr dayongkr commented Oct 23, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

ObjectKeys<T> runs every key through a template literal, so string enum keys widen to plain string literals. Since #2077 this also affects findKey and mapKeys (pickBy and omitBy since v1.52.0).

enum Status { Active = 'active', Inactive = 'inactive' }
const key = findKey({} as Record<Status, number>, v => v > 0);
// v1.52.0: Status | undefined
// main:    'active' | 'inactive' | undefined, which can't be passed where a Status is expected

Changes

  • ObjectKeys<T> keeps string keys as they are and converts only numeric keys to strings, so string enums stay intact.
  • Tests for string and numeric enums, enum keys in findKey and mapKeys, and string methods on keys of a generic object type.
  • An enum example in the ObjectKeys docs (en, ko, ja, zh_hans).

… string literals

`${Exclude<keyof T, symbol>}` turned every string key into a string literal,
so `findKey`, `mapKeys`, `pickBy`, and `omitBy` on a `Record<Status, T>`
handed back `'active' | 'inactive'` instead of `Status`, and code that passed
the key back into a `Status` parameter stopped compiling. String keys are now
extracted as they are, and only numeric keys go through a template literal.
Keys of a generic object type still support string methods.
@vercel

vercel Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
es-toolkit Ready Ready Preview Oct 23, 2026 9:42am UTC

Request Review

@dayongkr
dayongkr marked this pull request as ready for review October 23, 2026 09:13
@dayongkr
dayongkr requested a review from raon0211 as a code owner October 23, 2026 09:13
@dayongkr
dayongkr merged commit cf6fd18 into main Oct 23, 2026
11 of 12 checks passed

This branch was successfully deployed

1 active deployment
Preview — 94b73f8e Deployed Oct 23, 2026 by vercel[bot]
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