main
Last change
on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago |
Initial commit
|
-
Property mode
set to
100644
|
File size:
1012 bytes
|
Line | |
---|
1 | import {Except} from './except';
|
---|
2 | import {ConditionalKeys} from './conditional-keys';
|
---|
3 |
|
---|
4 | /**
|
---|
5 | Exclude keys from a shape that matches the given `Condition`.
|
---|
6 |
|
---|
7 | This 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 | ```
|
---|
11 | import {Primitive, ConditionalExcept} from 'type-fest';
|
---|
12 |
|
---|
13 | class Awesome {
|
---|
14 | name: string;
|
---|
15 | successes: number;
|
---|
16 | failures: bigint;
|
---|
17 |
|
---|
18 | run() {}
|
---|
19 | }
|
---|
20 |
|
---|
21 | type ExceptPrimitivesFromAwesome = ConditionalExcept<Awesome, Primitive>;
|
---|
22 | //=> {run: () => void}
|
---|
23 | ```
|
---|
24 |
|
---|
25 | @example
|
---|
26 | ```
|
---|
27 | import {ConditionalExcept} from 'type-fest';
|
---|
28 |
|
---|
29 | interface Example {
|
---|
30 | a: string;
|
---|
31 | b: string | number;
|
---|
32 | c: () => void;
|
---|
33 | d: {};
|
---|
34 | }
|
---|
35 |
|
---|
36 | type NonStringKeysOnly = ConditionalExcept<Example, string>;
|
---|
37 | //=> {b: string | number; c: () => void; d: {}}
|
---|
38 | ```
|
---|
39 | */
|
---|
40 | export type ConditionalExcept<Base, Condition> = Except<
|
---|
41 | Base,
|
---|
42 | ConditionalKeys<Base, Condition>
|
---|
43 | >;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.