Skip to content
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

Proposal: StringKeyof #341

Closed
younho9 opened this issue Jan 3, 2022 · 1 comment · Fixed by #344
Closed

Proposal: StringKeyof #341

younho9 opened this issue Jan 3, 2022 · 1 comment · Fixed by #344
Labels
help wanted Extra attention is needed type addition

Comments

@younho9
Copy link
Contributor

younho9 commented Jan 3, 2022

keyof object could include number type. (It is intended.)

However, sometimes we want to get only string keys. (https://github.com/sindresorhus/type-fest/blob/main/source/get.d.ts#L68-L70)

How about provide StringKeyof type for this use cases?

type StringKeyof<BaseType> = `${Extract<keyof BaseType, string | number>}`

See also:

@sindresorhus
Copy link
Owner

I would argue that you almost always want only the string keys, so this sounds useful indeed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed type addition
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants