-
Notifications
You must be signed in to change notification settings - Fork 520
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make KeyPaths not require @ts-ignore (#1842)
* Fix type of KeyPaths to not require ts-ignore * Only recursive into records in KeyPaths * Fix imports in keypaths test * Add patch changeset for KeyPaths
- Loading branch information
Showing
2 changed files
with
7 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |