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

Make KeyPaths not require @ts-ignore #1842

Merged
merged 6 commits into from
Feb 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/modern-humans-type.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/react': patch
---

Allow `KeyPaths` type to accept any type in order to remove need for `// @ts-ignore` internally.
10 changes: 2 additions & 8 deletions src/utils/types/KeyPaths.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
// Produces a union of dot-delimited keypaths to the string values in a nested object:
export type KeyPaths<O extends Record<string, unknown>> = {
[K in keyof O]: K extends string
? O[K] extends string
? `${K}`
: // eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore TypeScript has bested me, but the KeyPaths type is tested.
`${K}.${KeyPaths<O[K]>}`
: never
export type KeyPaths<O> = {
[K in keyof O]: K extends string ? (O[K] extends Record<string, unknown> ? `${K}.${KeyPaths<O[K]>}` : `${K}`) : never
}[keyof O]