import { type ConditionalKeys } from "https://dotland.deno.dev/x/scaffold@0.3.0/src/deps/types.ts";
Extract the keys from a type where the value type of the key extends the given Condition
.
Internally this is used for the ConditionalPick
and ConditionalExcept
types.
Examples
Example 1
Example 1
import type {ConditionalKeys} from 'type-fest';
interface Example {
a: string;
b: string | number;
c?: string;
d: {};
}
type StringKeysOnly = ConditionalKeys<Example, string>;
//=> 'a'
To support partial types, make sure your Condition
is a union of undefined (for example, string | undefined
) as demonstrated below.