Skip to content

Commit

Permalink
ConditionalKeys: fix compatibility with TypeScript 5.4 (#852)
Browse files Browse the repository at this point in the history
  • Loading branch information
Emiyaaaaa committed Apr 2, 2024
1 parent b6d8dd6 commit 0fb2d62
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
8 changes: 3 additions & 5 deletions source/conditional-keys.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,10 @@ type StringKeysAndUndefined = ConditionalKeys<Example, string | undefined>;
@category Object
*/
export type ConditionalKeys<Base, Condition> = NonNullable<
// Wrap in `NonNullable` to strip away the `undefined` type from the produced union.
export type ConditionalKeys<Base, Condition> =
{
// Map through all the keys of the given base type.
[Key in keyof Base]:
[Key in keyof Base]-?:
// Pick only keys with types extending the given `Condition` type.
Base[Key] extends Condition
// Retain this key since the condition passes.
Expand All @@ -43,5 +42,4 @@ export type ConditionalKeys<Base, Condition> = NonNullable<
: never;

// Convert the produced object into a union type of the keys which passed the conditional test.
}[keyof Base]
>;
}[keyof Base];
3 changes: 1 addition & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
"useDefineForClassFields": true,
},
"exclude": [
// Ignore `ConditionalKeys` and `WriteableDeep` error temporarily, remove when #831 and #833 are fixed.
"test-d/conditional-keys.ts",
// Ignore `WriteableDeep` error temporarily, remove when #833 are fixed.
"test-d/writable-deep.ts",
]
}

0 comments on commit 0fb2d62

Please sign in to comment.