source: trip-planner-front/node_modules/type-fest/source/set-required.d.ts

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

initial commit

  • Property mode set to 100644
File size: 914 bytes
Line 
1import {Except} from './except';
2import {Simplify} from './simplify';
3
4/**
5Create a type that makes the given keys required. The remaining keys are kept as is. The sister of the `SetOptional` type.
6
7Use-case: You want to define a single model where the only thing that changes is whether or not some of the keys are required.
8
9@example
10```
11import {SetRequired} from 'type-fest';
12
13type Foo = {
14 a?: number;
15 b: string;
16 c?: boolean;
17}
18
19type SomeRequired = SetRequired<Foo, 'b' | 'c'>;
20// type SomeRequired = {
21// a?: number;
22// b: string; // Was already required and still is.
23// c: boolean; // Is now required.
24// }
25```
26*/
27export type SetRequired<BaseType, Keys extends keyof BaseType> =
28 Simplify<
29 // Pick just the keys that are optional from the base type.
30 Except<BaseType, Keys> &
31 // Pick the keys that should be required from the base type and make them required.
32 Required<Pick<BaseType, Keys>>
33 >;
Note: See TracBrowser for help on using the repository browser.