Skip to content

Commit 33ffdcf

Browse files
committed
refactor: improve type documentation and add Simplify type definition
1 parent 25e4f02 commit 33ffdcf

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

packages/type-helper/types.d.ts

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@ declare global {
4545
type Maybe<T> = T | undefined;
4646

4747
/**
48-
* Represents a value that can be of type `T` or a Promise that resolves to `T`.
48+
* Represents a value that can be of type `T` or a Promise that resolves to `T`.
4949
* A more idiomatic name for `MaybePromise`.
5050
* @template T The type of the value.
5151
* @example
5252
* async function process(data: Awaitable<string>) {
53-
* const resolvedData = await data;
54-
* console.log(resolvedData);
53+
* const resolvedData = await data;
54+
* console.log(resolvedData);
5555
* }
5656
*/
5757
type Awaitable<T> = T | Promise<T>;
@@ -61,8 +61,8 @@ declare global {
6161
* @template T The type of the item(s).
6262
* @example
6363
* function logItems(items: SingleOrArray<string>) {
64-
* const allItems = Array.isArray(items) ? items : [items];
65-
* allItems.forEach(item => console.log(item));
64+
* const allItems = Array.isArray(items) ? items : [items];
65+
* allItems.forEach(item => console.log(item));
6666
* }
6767
*/
6868
type SingleOrArray<T> = T | T[];
@@ -77,7 +77,6 @@ declare global {
7777

7878
/**
7979
* Returns the keys of an object type `T` that are required (not optional).
80-
*
8180
* @template T - The object type.
8281
* @returns The keys of `T` that are required.
8382
*/
@@ -87,7 +86,6 @@ declare global {
8786

8887
/**
8988
* Returns the keys of an object type `T` that are optional.
90-
*
9189
* @template T - The object type.
9290
* @returns The keys of `T` that are optional.
9391
*/
@@ -121,7 +119,6 @@ declare global {
121119

122120
/**
123121
* Recursively makes all properties of an object and its nested objects/array required.
124-
*
125122
* @template T - The type to make deep required.
126123
* @param {T} value - The value to make deep required.
127124
* @returns {DeepRequired<T>} - The deep required type.
@@ -184,7 +181,7 @@ declare global {
184181
type ObjectValues<T> = T[keyof T];
185182

186183
/**
187-
* Extracts the item type from an array (including readonly arrays).
184+
* Extracts the item type from an array (including readonly arrays).
188185
* Returns `never` if `T` is not an array.
189186
* @template T The array type.
190187
* @example
@@ -204,6 +201,14 @@ declare global {
204201
*/
205202
type Overwrite<M, N> = Omit<M, keyof N> & N;
206203

204+
/**
205+
* Flattens a complex type into a simple object representation (بکش از ما بیرون).
206+
* Useful for improving editor tooltips for complex intersection and mapped types.
207+
* And also to transform an interface into a type to aide with assignability.
208+
* @template T The type to simplify.
209+
*/
210+
type Simplify<T> = { [K in keyof T]: T[K] } & {};
211+
207212
/**
208213
* Make all properties in T required and exclude undefined and null from the property type.
209214
*/
@@ -287,13 +292,5 @@ declare global {
287292
[Key in keyof Pick<T, FilterJsonifiableKeys<T>>]: T[Key];
288293
};
289294

290-
/**
291-
* Convert simple type (بکش از ما بیرون).
292-
* Useful to flatten the type output to improve type hints shown in editors.
293-
* And also to transform an interface into a type to aide with assignability.
294-
*
295-
* @template T - The type to be simplified.
296-
* @returns The simplified type.
297-
*/
298-
type Simplify<T> = {[KeyType in keyof T]: T[KeyType]} & {};
295+
299296
}

0 commit comments

Comments
 (0)