Skip to content

Commit

Permalink
Merge pull request #1321 from demergent-labs/tuple_recursion_types
Browse files Browse the repository at this point in the history
introduce base case and 11 levels for tuple recursion
  • Loading branch information
lastmjs authored Oct 2, 2023
2 parents 6eae4f0 + cd2fc25 commit 1dff831
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions src/lib_functional/candid/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ import {
AzleVoid
} from '../../lib_new';

export type TypeMapping<T> = T extends () => any
export type TypeMapping<T, RecursionLevel = 0> = RecursionLevel extends 10
? T
: T extends () => any
? ReturnType<T>
: T extends AzleText
? string
Expand Down Expand Up @@ -77,7 +79,30 @@ export type TypeMapping<T> = T extends () => any
: T extends AzleVoid
? void
: T extends AzleTuple<infer U>
? { [K in keyof U]: U[K] extends any ? any : TypeMapping<U[K]> }
? {
[K in keyof U]: TypeMapping<
U[K],
RecursionLevel extends 0
? 1
: RecursionLevel extends 1
? 2
: RecursionLevel extends 2
? 3
: RecursionLevel extends 3
? 4
: RecursionLevel extends 4
? 5
: RecursionLevel extends 5
? 6
: RecursionLevel extends 6
? 7
: RecursionLevel extends 8
? 9
: RecursionLevel extends 9
? 10
: 10
>;
}
: T extends AzleVec<infer U>
? TypeMapping<U>[]
: T extends AzleOpt<infer U>
Expand Down

0 comments on commit 1dff831

Please sign in to comment.