1 | import { SetComplement, DeepReadonly } from './mapped-types';
|
2 | /**
|
3 | * $Keys
|
4 | * @desc Get the union type of all the keys in an object type `T`
|
5 | * @see https://flow.org/en/docs/types/utilities/#toc-keys
|
6 | * @example
|
7 | * type Props = { name: string; age: number; visible: boolean };
|
8 | *
|
9 | * // Expect: "name" | "age" | "visible"
|
10 | * type PropsKeys = $Keys<Props>;
|
11 | */
|
12 | export declare type $Keys<T extends object> = keyof T;
|
13 | /**
|
14 | * $Values
|
15 | * @desc Get the union type of all the values in an object type `T`
|
16 | * @see https://flow.org/en/docs/types/utilities/#toc-values
|
17 | * @example
|
18 | * type Props = { name: string; age: number; visible: boolean };
|
19 | *
|
20 | * // Expect: string | number | boolean
|
21 | * type PropsValues = $Values<Props>;
|
22 | */
|
23 | export declare type $Values<T extends object> = T[keyof T];
|
24 | /**
|
25 | * $ReadOnly
|
26 | * @desc Get the read-only version of a given object type `T` (it works on nested data structure)
|
27 | * @see https://flow.org/en/docs/types/utilities/#toc-readonly
|
28 | * @example
|
29 | * type Props = { name: string; age: number; visible: boolean };
|
30 | *
|
31 | * // Expect: Readonly<{ name: string; age: number; visible: boolean; }>
|
32 | * type ReadOnlyProps = $ReadOnly<Props>;
|
33 | */
|
34 | export declare type $ReadOnly<T extends object> = DeepReadonly<T>;
|
35 | /**
|
36 | * $Diff
|
37 | * @desc Get the set difference of a given object types `T` and `U` (`T \ U`)
|
38 | * @see https://flow.org/en/docs/types/utilities/#toc-diff
|
39 | * @example
|
40 | * type Props = { name: string; age: number; visible: boolean };
|
41 | * type DefaultProps = { age: number };
|
42 | *
|
43 | * // Expect: { name: string; visible: boolean; }
|
44 | * type RequiredProps = Diff<Props, DefaultProps>;
|
45 | */
|
46 | export declare type $Diff<T extends U, U extends object> = Pick<T, SetComplement<keyof T, keyof U>>;
|
47 | /**
|
48 | * $PropertyType
|
49 | * @desc Get the type of property of an object at a given key `K`
|
50 | * @see https://flow.org/en/docs/types/utilities/#toc-propertytype
|
51 | * @example
|
52 | * // Expect: string;
|
53 | * type Props = { name: string; age: number; visible: boolean };
|
54 | * type NameType = $PropertyType<Props, 'name'>;
|
55 | *
|
56 | * // Expect: boolean
|
57 | * type Tuple = [boolean, number];
|
58 | * type A = $PropertyType<Tuple, '0'>;
|
59 | * // Expect: number
|
60 | * type B = $PropertyType<Tuple, '1'>;
|
61 | */
|
62 | export declare type $PropertyType<T extends object, K extends keyof T> = T[K];
|
63 | /**
|
64 | * $ElementType
|
65 | * @desc Get the type of elements inside of array, tuple or object of type `T`, that matches the given index type `K`
|
66 | * @see https://flow.org/en/docs/types/utilities/#toc-elementtype
|
67 | * @example
|
68 | * // Expect: string;
|
69 | * type Props = { name: string; age: number; visible: boolean };
|
70 | * type NameType = $ElementType<Props, 'name'>;
|
71 | *
|
72 | * // Expect: boolean
|
73 | * type Tuple = [boolean, number];
|
74 | * type A = $ElementType<Tuple, '0'>;
|
75 | * // Expect: number
|
76 | * type B = $ElementType<Tuple, '1'>;
|
77 | *
|
78 | * // Expect: boolean
|
79 | * type Arr = boolean[];
|
80 | * type ItemsType = $ElementType<Arr, number>;
|
81 | *
|
82 | * // Expect: number
|
83 | * type Obj = { [key: string]: number };
|
84 | * type ValuesType = $ElementType<Obj, string>;
|
85 | */
|
86 | export declare type $ElementType<T extends {
|
87 | [P in K & any]: any;
|
88 | }, K extends keyof T | number> = T[K];
|
89 | /**
|
90 | * $Call
|
91 | * @desc Get the return type from a given typeof expression
|
92 | * @see https://flow.org/en/docs/types/utilities/#toc-call
|
93 | * @example
|
94 | * // Common use-case
|
95 | * const add = (amount: number) => ({ type: 'ADD' as 'ADD', payload: amount });
|
96 | * type AddAction = $Call<typeof add>; // { type: 'ADD'; payload: number }
|
97 | *
|
98 | * // Examples migrated from Flow docs
|
99 | * type ExtractPropType<T extends { prop: any }> = (arg: T) => T['prop'];
|
100 | * type Obj = { prop: number };
|
101 | * type PropType = $Call<ExtractPropType<Obj>>; // number
|
102 | *
|
103 | * type ExtractReturnType<T extends () => any> = (arg: T) => ReturnType<T>;
|
104 | * type Fn = () => number;
|
105 | * type FnReturnType = $Call<ExtractReturnType<Fn>>; // number
|
106 | */
|
107 | export declare type $Call<Fn extends (...args: any[]) => any> = Fn extends (arg: any) => infer RT ? RT : never;
|
108 | /**
|
109 | * $Shape
|
110 | * @desc Copies the shape of the type supplied, but marks every field optional.
|
111 | * @see https://flow.org/en/docs/types/utilities/#toc-shape
|
112 | * @example
|
113 | * type Props = { name: string; age: number; visible: boolean };
|
114 | *
|
115 | * // Expect: Partial<Props>
|
116 | * type PartialProps = $Shape<Props>;
|
117 | */
|
118 | export declare type $Shape<T extends object> = Partial<T>;
|
119 | /**
|
120 | * $NonMaybeType
|
121 | * @desc Excludes null and undefined from T
|
122 | * @see https://flow.org/en/docs/types/utilities/#toc-nonmaybe
|
123 | * @example
|
124 | * type MaybeName = string | null;
|
125 | *
|
126 | * // Expect: string
|
127 | * type Name = $NonMaybeType<MaybeName>;
|
128 | */
|
129 | export declare type $NonMaybeType<T> = NonNullable<T>;
|
130 | /**
|
131 | * Class
|
132 | * @desc Represents constructor of type T
|
133 | * @see https://flow.org/en/docs/types/utilities/#toc-class
|
134 | * @example
|
135 | * class Store {}
|
136 | * function makeStore(storeClass: Class<Store>): Store {
|
137 | * return new storeClass();
|
138 | * }
|
139 | */
|
140 | export declare type Class<T> = new (...args: any[]) => T;
|
141 | /**
|
142 | * mixed
|
143 | * @desc An arbitrary type that could be anything
|
144 | * @see https://flow.org/en/docs/types/mixed
|
145 | * @example
|
146 | *
|
147 | * function stringify(value: mixed) {
|
148 | * // ...
|
149 | * }
|
150 | *
|
151 | * stringify("foo");
|
152 | * stringify(3.14);
|
153 | * stringify(null);
|
154 | * stringify({});
|
155 | */
|
156 | export declare type mixed = unknown;
|