-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #123 from ThomasAribart/fix-bug-with-compute-type-…
…util fix bug with Compute type util
- Loading branch information
Showing
5 changed files
with
38 additions
and
10 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 |
---|---|---|
@@ -1,9 +1,33 @@ | ||
export type Compute<A> = A extends Promise<infer T> | ||
? Promise<Compute<T>> | ||
: A extends (...args: infer P) => infer R | ||
? (...args: Compute<P>) => Compute<R> | ||
: A extends Set<infer V> | ||
? Set<Compute<V>> | ||
: A extends object | ||
? { [key in keyof A]: Compute<A[key]> } | ||
: A; | ||
import type { DoesExtend } from "./extends"; | ||
import type { If } from "./if"; | ||
import type { Key } from "./key"; | ||
|
||
export type Compute<A, Seen = never> = A extends | ||
| Function | ||
| Error | ||
| Date | ||
| { readonly [Symbol.toStringTag]: string } | ||
| RegExp | ||
| Generator | ||
? A | ||
: If< | ||
DoesExtend<Seen, A>, | ||
A, | ||
A extends Array<unknown> | ||
? A extends Array<Record<Key, unknown>> | ||
? Array< | ||
{ | ||
[K in keyof A[number]]: Compute<A[number][K], A | Seen>; | ||
} & unknown | ||
> | ||
: A | ||
: A extends ReadonlyArray<unknown> | ||
? A extends ReadonlyArray<Record<string | number | symbol, unknown>> | ||
? ReadonlyArray< | ||
{ | ||
[K in keyof A[number]]: Compute<A[number][K], A | Seen>; | ||
} & unknown | ||
> | ||
: A | ||
: { [K in keyof A]: Compute<A[K], A | Seen> } & unknown | ||
>; |
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
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 @@ | ||
export type If<B extends boolean, T, E = never> = B extends true ? T : E; |
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
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 @@ | ||
export type Key = string | number | symbol; |