-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: đź“ť update readme for missing pkgs; add JS/TS notes
- Loading branch information
Showing
3 changed files
with
44 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# JavaScript and TypeScript Notes | ||
|
||
The following is a type definition for a conversion roundtrip from obj to json to obj.\ | ||
@see {@link https://effectivetypescript.com/2020/04/09/jsonify/} | ||
|
||
```ts | ||
// export type JsonifySimple<T> = T extends { toJSON(): infer U } | ||
// ? U | ||
// : T extends object | ||
// ? { [k in keyof T]: Jsonify<T[k]> } | ||
// : T; | ||
|
||
export type Jsonify<T> = T extends { toJSON: (...args: any) => infer R } | ||
? Jsonify<R> | ||
: T extends Array<infer I> | ||
? Array<Jsonify<I>> | ||
: T extends (...args: any) => any | ||
? never | ||
: T extends object | ||
? { [K in keyof T]: K extends string | number ? Jsonify<T[K]> : never } | ||
: T; | ||
``` | ||
|
||
--- | ||
|
||
Get the single type of an array type e.g: User[] -> User | ||
|
||
```ts | ||
type GetElementType<T extends any[]> = T extends (infer U)[] ? U : never; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.