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

ConditionalKeys: fix compatibility with TypeScript 5.4 #852

Merged
merged 1 commit into from
Apr 2, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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",
]
}