source: trip-planner-front/node_modules/type-fest/source/conditional-pick.d.ts@ ceaed42

Last change on this file since ceaed42 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 933 bytes
Line 
1import {ConditionalKeys} from './conditional-keys';
2
3/**
4Pick keys from the shape that matches the given `Condition`.
5
6This is useful when you want to create a new type from a specific subset of an existing type. For example, you might want to pick all the primitive properties from a class and form a new automatically derived type.
7
8@example
9```
10import {Primitive, ConditionalPick} from 'type-fest';
11
12class Awesome {
13 name: string;
14 successes: number;
15 failures: bigint;
16
17 run() {}
18}
19
20type PickPrimitivesFromAwesome = ConditionalPick<Awesome, Primitive>;
21//=> {name: string; successes: number; failures: bigint}
22```
23
24@example
25```
26import {ConditionalPick} from 'type-fest';
27
28interface Example {
29 a: string;
30 b: string | number;
31 c: () => void;
32 d: {};
33}
34
35type StringKeysOnly = ConditionalPick<Example, string>;
36//=> {a: string}
37```
38*/
39export type ConditionalPick<Base, Condition> = Pick<
40 Base,
41 ConditionalKeys<Base, Condition>
42>;
Note: See TracBrowser for help on using the repository browser.