diff --git a/tests/cases/user/ts-toolbelt/index.ts b/tests/cases/user/ts-toolbelt/index.ts new file mode 100644 index 0000000000000..218db6ba38dc0 --- /dev/null +++ b/tests/cases/user/ts-toolbelt/index.ts @@ -0,0 +1,44 @@ +// ! this library is mostly used with ramda + +import {I, T, Test} from "ts-toolbelt"; + +const {check, checks} = Test; + +// iterates over `T` and returns the `Iteration` position when finished +type StdRecursiveIteration> = { + 0: StdRecursiveIteration>; + 1: I.Pos; +}[ + I.Pos extends T.Length // this form of recursion is preferred + ? 1 // because it will let the user know if + : 0 // the instantiation depth has been hit +]; // (but error is sometimes swallowed (?)) + +checks([ + check, 40, Test.Pass>(), // max length is 40 +]); + +// iterates over `T` and returns the `Iteration` position when finished +type SafeRecursiveIteration> = { + 0: SafeRecursiveIteration>; + 1: I.Pos; +}[ + I.Key extends T.Length // this form of recursion is the safest + ? 1 // because `T.Length` will force + : 0 // the length to comply with the limits +]; // => won't compute if excessive length + +checks([ + check, 0, Test.Pass>() // did not compute +]); diff --git a/tests/cases/user/ts-toolbelt/package.json b/tests/cases/user/ts-toolbelt/package.json new file mode 100644 index 0000000000000..d066aeec2d688 --- /dev/null +++ b/tests/cases/user/ts-toolbelt/package.json @@ -0,0 +1,14 @@ +{ + "name": "ts-toolbelt-test", + "version": "1.0.0", + "description": "", + "author": "", + "license": "Apache-2.0", + "repository": { + "type": "git", + "url": "https://github.com/pirix-gh/ts-toolbelt" + }, + "dependencies": { + "ts-toolbelt": "latest" + } +} diff --git a/tests/cases/user/ts-toolbelt/tsconfig.json b/tests/cases/user/ts-toolbelt/tsconfig.json new file mode 100644 index 0000000000000..fc0c19189c360 --- /dev/null +++ b/tests/cases/user/ts-toolbelt/tsconfig.json @@ -0,0 +1,5 @@ +{ + "compilerOptions": { + "strict": true + } +}