From 7eca8a46147ac91833f4dfeba4be70c9086e6513 Mon Sep 17 00:00:00 2001 From: Jonathan Clem Date: Fri, 4 Feb 2022 15:39:53 -0500 Subject: [PATCH 1/4] Fix type of KeyPaths to not require ts-ignore --- src/utils/types/KeyPaths.ts | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/utils/types/KeyPaths.ts b/src/utils/types/KeyPaths.ts index e35c954d1fb..3e5368406cb 100644 --- a/src/utils/types/KeyPaths.ts +++ b/src/utils/types/KeyPaths.ts @@ -1,10 +1,4 @@ // Produces a union of dot-delimited keypaths to the string values in a nested object: -export type KeyPaths> = { - [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}` - : never +export type KeyPaths = { + [K in keyof O]: K extends string ? (O[K] extends string ? `${K}` : `${K}.${KeyPaths}`) : never }[keyof O] From 65f55d0a80f19b4ce8093596c25a15b0771068f4 Mon Sep 17 00:00:00 2001 From: Jonathan Clem Date: Fri, 4 Feb 2022 15:44:28 -0500 Subject: [PATCH 2/4] Only recursive into records in KeyPaths --- src/__tests__/KeyPaths.types.test.ts | 2 +- src/utils/types/KeyPaths.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/__tests__/KeyPaths.types.test.ts b/src/__tests__/KeyPaths.types.test.ts index 19ac52e4040..6123319b4ba 100644 --- a/src/__tests__/KeyPaths.types.test.ts +++ b/src/__tests__/KeyPaths.types.test.ts @@ -1,5 +1,5 @@ import {Union} from 'ts-toolbelt' -import {KeyPaths} from '../utils/types/KeyPaths' +import {KeyPaths, KP} from '../utils/types/KeyPaths' type NestedObject = { a: string diff --git a/src/utils/types/KeyPaths.ts b/src/utils/types/KeyPaths.ts index 3e5368406cb..c76f7b5087c 100644 --- a/src/utils/types/KeyPaths.ts +++ b/src/utils/types/KeyPaths.ts @@ -1,4 +1,4 @@ // Produces a union of dot-delimited keypaths to the string values in a nested object: export type KeyPaths = { - [K in keyof O]: K extends string ? (O[K] extends string ? `${K}` : `${K}.${KeyPaths}`) : never + [K in keyof O]: K extends string ? (O[K] extends Record ? `${K}.${KeyPaths}` : `${K}`) : never }[keyof O] From 4f81e0d016cc0e948c0df91a1acd9f10447e22e7 Mon Sep 17 00:00:00 2001 From: Jonathan Clem Date: Fri, 4 Feb 2022 15:53:19 -0500 Subject: [PATCH 3/4] Fix imports in keypaths test --- src/__tests__/KeyPaths.types.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/__tests__/KeyPaths.types.test.ts b/src/__tests__/KeyPaths.types.test.ts index 6123319b4ba..19ac52e4040 100644 --- a/src/__tests__/KeyPaths.types.test.ts +++ b/src/__tests__/KeyPaths.types.test.ts @@ -1,5 +1,5 @@ import {Union} from 'ts-toolbelt' -import {KeyPaths, KP} from '../utils/types/KeyPaths' +import {KeyPaths} from '../utils/types/KeyPaths' type NestedObject = { a: string From a3eec056bbeee91a695523e1046f7b6f9dbb4649 Mon Sep 17 00:00:00 2001 From: Jonathan Clem Date: Fri, 4 Feb 2022 15:55:19 -0500 Subject: [PATCH 4/4] Add patch changeset for KeyPaths --- .changeset/modern-humans-type.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/modern-humans-type.md diff --git a/.changeset/modern-humans-type.md b/.changeset/modern-humans-type.md new file mode 100644 index 00000000000..904f3383e16 --- /dev/null +++ b/.changeset/modern-humans-type.md @@ -0,0 +1,5 @@ +--- +'@primer/react': patch +--- + +Allow `KeyPaths` type to accept any type in order to remove need for `// @ts-ignore` internally.