UNPKG

1.05 kBTypeScriptView Raw
1import type {Except} from './except';
2import type {ConditionalKeys} from './conditional-keys';
3
4/**
5Exclude keys from a shape that matches the given `Condition`.
6
7This is useful when you want to create a new type with a specific set of keys from a shape. For example, you might want to exclude all the primitive properties from a class and form a new shape containing everything but the primitive properties.
8
9@example
10```
11import type {Primitive, ConditionalExcept} from 'type-fest';
12
13class Awesome {
14 name: string;
15 successes: number;
16 failures: bigint;
17
18 run() {}
19}
20
21type ExceptPrimitivesFromAwesome = ConditionalExcept<Awesome, Primitive>;
22//=> {run: () => void}
23```
24
25@example
26```
27import type {ConditionalExcept} from 'type-fest';
28
29interface Example {
30 a: string;
31 b: string | number;
32 c: () => void;
33 d: {};
34}
35
36type NonStringKeysOnly = ConditionalExcept<Example, string>;
37//=> {b: string | number; c: () => void; d: {}}
38```
39
40@category Object
41*/
42export type ConditionalExcept<Base, Condition> = Except<
43Base,
44ConditionalKeys<Base, Condition>
45>;