mirror of
https://github.com/XiaoDaiGua-Ray/ray-template.git
synced 2025-04-06 03:57:49 +08:00
19 lines
681 B
TypeScript
19 lines
681 B
TypeScript
export type ConditionalKeys<Base, Condition> = NonNullable<
|
|
// Wrap in `NonNullable` to strip away the `undefined` type from the produced union.
|
|
{
|
|
// Map through all the keys of the given base type.
|
|
[Key in keyof Base]: Base[Key] extends Condition // Pick only keys with types extending the given `Condition` type.
|
|
? // Retain this key since the condition passes.
|
|
Key
|
|
: // Discard this key since the condition fails.
|
|
never
|
|
|
|
// Convert the produced object into a union type of the keys which passed the conditional test.
|
|
}[keyof Base]
|
|
>
|
|
|
|
export type ConditionalPick<Base, Condition> = Pick<
|
|
Base,
|
|
ConditionalKeys<Base, Condition>
|
|
>
|