diff --git a/package-lock.json b/package-lock.json index 98284bf8..0af33edd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -27,6 +27,7 @@ "rollup-plugin-typescript2": "^0.32.1", "testdouble": "3.16.3", "ts-jest": "27.1.5", + "ts-toolbelt": "9.6.0", "tslib": "^2.4.0", "typescript": "4.7.2" } @@ -12765,6 +12766,12 @@ "node": ">=10" } }, + "node_modules/ts-toolbelt": { + "version": "9.6.0", + "resolved": "https://registry.npmjs.org/ts-toolbelt/-/ts-toolbelt-9.6.0.tgz", + "integrity": "sha512-nsZd8ZeNUzukXPlJmTBwUAuABDe/9qtVDelJeT/qW0ow3ZS3BsQJtNkan1802aM9Uf68/Y8ljw86Hu0h5IUW3w==", + "dev": true + }, "node_modules/tslib": { "version": "2.4.0", "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.4.0.tgz", @@ -22782,6 +22789,12 @@ } } }, + "ts-toolbelt": { + "version": "9.6.0", + "resolved": "https://registry.npmjs.org/ts-toolbelt/-/ts-toolbelt-9.6.0.tgz", + "integrity": "sha512-nsZd8ZeNUzukXPlJmTBwUAuABDe/9qtVDelJeT/qW0ow3ZS3BsQJtNkan1802aM9Uf68/Y8ljw86Hu0h5IUW3w==", + "dev": true + }, "tslib": { "version": "2.4.0", "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.4.0.tgz", diff --git a/package.json b/package.json index 60417524..d3bc20f1 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "types": "dist/index.d.ts", "scripts": { "test": "jest && npm run test-types", - "test-types": "tsc --noEmit ./tests/typecheck-tests.ts", + "test-types": "tsc --noEmit -p ./tests/tsconfig.tests.json", "lint": "eslint ./src --ext .ts", "format": "prettier --write 'src/**/*.ts?(x)' && npm run lint -- --fix", "typecheck": "tsc --noEmit", @@ -43,6 +43,7 @@ "rollup-plugin-typescript2": "^0.32.1", "testdouble": "3.16.3", "ts-jest": "27.1.5", + "ts-toolbelt": "9.6.0", "tslib": "^2.4.0", "typescript": "4.7.2" }, diff --git a/src/result.ts b/src/result.ts index 59edf442..c8f09971 100644 --- a/src/result.ts +++ b/src/result.ts @@ -346,6 +346,35 @@ type Prev = [ 18, 19, 20, + 21, + 22, + 23, + 24, + 25, + 26, + 27, + 28, + 29, + 30, + 31, + 32, + 33, + 34, + 35, + 36, + 37, + 38, + 39, + 40, + 41, + 42, + 43, + 44, + 45, + 46, + 47, + 48, + 49, ...0[] ] @@ -354,7 +383,7 @@ type Prev = [ // T - The array of the results // Collected - The collected tuples. // Depth - The maximum depth. -type CollectResults = [ +type CollectResults = [ Depth, ] extends [never] ? [] diff --git a/tests/tsconfig.tests.json b/tests/tsconfig.tests.json new file mode 100644 index 00000000..d9bc7db2 --- /dev/null +++ b/tests/tsconfig.tests.json @@ -0,0 +1,26 @@ +{ + "compilerOptions": { + "target": "es2016", + "module": "ES2015", + "noImplicitAny": true, + "sourceMap": false, + "downlevelIteration": true, + "noUnusedLocals": false, + "noUnusedParameters": false, + "strictNullChecks": true, + "strictFunctionTypes": true, + "declaration": true, + "moduleResolution": "Node", + "baseUrl": "./src", + "lib": [ + "dom", + "es2016", + "es2017.object" + ], + "outDir": "dist", + }, + "include": [ + "./index.test.ts", + "./typecheck-tests.ts" + ], +} diff --git a/tests/typecheck-tests.ts b/tests/typecheck-tests.ts index 8fd7ce70..849b2247 100644 --- a/tests/typecheck-tests.ts +++ b/tests/typecheck-tests.ts @@ -14,6 +14,24 @@ import { ResultAsync, } from '../src' import { Transpose } from '../src/result' +import { type N, Test } from 'ts-toolbelt' + +type CreateTuple = + // Length must always be a number + L extends number + ? N.IsNegative extends 1 + // Length must always be non-negative + ? never + // base case + : L extends 0 + ? [] + // recursion depth check + // typescript has a limit. + : N.Lower extends 1 + ? [V, ...CreateTuple, V>] + : never + : never; + (function describe(_ = 'Result') { (function describe(_ = 'andThen') { @@ -302,6 +320,536 @@ import { Transpose } from '../src/result' const assignableToCheck: Expectation = result; const assignablefromCheck: typeof result = assignableToCheck; }); + + (function describe(_ = 'inference on large tuples') { + (function it(_ = 'Should correctly infer the type on tuples with 6 elements') { + type Input = CreateTuple<6, Result> + type Expectation = Result, never> + + const inputValues = input() + const result = Result.combine(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 7 elements') { + type Input = CreateTuple<7, Result> + type Expectation = Result, never> + + const inputValues = input() + const result = Result.combine(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 8 elements') { + type Input = CreateTuple<8, Result> + type Expectation = Result, never> + + const inputValues = input() + const result = Result.combine(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 9 elements') { + type Input = CreateTuple<9, Result> + type Expectation = Result, never> + + const inputValues = input() + const result = Result.combine(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 10 elements') { + type Input = CreateTuple<10, Result> + type Expectation = Result, never> + + const inputValues = input() + const result = Result.combine(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 11 elements') { + type Input = CreateTuple<11, Result> + type Expectation = Result, never> + + const inputValues = input() + const result = Result.combine(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 12 elements') { + type Input = CreateTuple<12, Result> + type Expectation = Result, never> + + const inputValues = input() + const result = Result.combine(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 13 elements') { + type Input = CreateTuple<13, Result> + type Expectation = Result, never> + + const inputValues = input() + const result = Result.combine(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 14 elements') { + type Input = CreateTuple<14, Result> + type Expectation = Result, never> + + const inputValues = input() + const result = Result.combine(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 15 elements') { + type Input = CreateTuple<15, Result> + type Expectation = Result, never> + + const inputValues = input() + const result = Result.combine(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 16 elements') { + type Input = CreateTuple<16, Result> + type Expectation = Result, never> + + const inputValues = input() + const result = Result.combine(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 17 elements') { + type Input = CreateTuple<17, Result> + type Expectation = Result, never> + + const inputValues = input() + const result = Result.combine(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 18 elements') { + type Input = CreateTuple<18, Result> + type Expectation = Result, never> + + const inputValues = input() + const result = Result.combine(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 19 elements') { + type Input = CreateTuple<19, Result> + type Expectation = Result, never> + + const inputValues = input() + const result = Result.combine(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 20 elements') { + type Input = CreateTuple<20, Result> + type Expectation = Result, never> + + const inputValues = input() + const result = Result.combine(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 21 elements') { + type Input = CreateTuple<21, Result> + type Expectation = Result, never> + + const inputValues = input() + const result = Result.combine(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 22 elements') { + type Input = CreateTuple<22, Result> + type Expectation = Result, never> + + const inputValues = input() + const result = Result.combine(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 23 elements') { + type Input = CreateTuple<23, Result> + type Expectation = Result, never> + + const inputValues = input() + const result = Result.combine(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 24 elements') { + type Input = CreateTuple<24, Result> + type Expectation = Result, never> + + const inputValues = input() + const result = Result.combine(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 25 elements') { + type Input = CreateTuple<25, Result> + type Expectation = Result, never> + + const inputValues = input() + const result = Result.combine(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 26 elements') { + type Input = CreateTuple<26, Result> + type Expectation = Result, never> + + const inputValues = input() + const result = Result.combine(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 27 elements') { + type Input = CreateTuple<27, Result> + type Expectation = Result, never> + + const inputValues = input() + const result = Result.combine(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 28 elements') { + type Input = CreateTuple<28, Result> + type Expectation = Result, never> + + const inputValues = input() + const result = Result.combine(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 29 elements') { + type Input = CreateTuple<29, Result> + type Expectation = Result, never> + + const inputValues = input() + const result = Result.combine(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 30 elements') { + type Input = CreateTuple<30, Result> + type Expectation = Result, never> + + const inputValues = input() + const result = Result.combine(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 31 elements') { + type Input = CreateTuple<31, Result> + type Expectation = Result, never> + + const inputValues = input() + const result = Result.combine(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 32 elements') { + type Input = CreateTuple<32, Result> + type Expectation = Result, never> + + const inputValues = input() + const result = Result.combine(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 33 elements') { + type Input = CreateTuple<33, Result> + type Expectation = Result, never> + + const inputValues = input() + const result = Result.combine(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 34 elements') { + type Input = CreateTuple<34, Result> + type Expectation = Result, never> + + const inputValues = input() + const result = Result.combine(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 35 elements') { + type Input = CreateTuple<35, Result> + type Expectation = Result, never> + + const inputValues = input() + const result = Result.combine(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 36 elements') { + type Input = CreateTuple<36, Result> + type Expectation = Result, never> + + const inputValues = input() + const result = Result.combine(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 37 elements') { + type Input = CreateTuple<37, Result> + type Expectation = Result, never> + + const inputValues = input() + const result = Result.combine(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 38 elements') { + type Input = CreateTuple<38, Result> + type Expectation = Result, never> + + const inputValues = input() + const result = Result.combine(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 39 elements') { + type Input = CreateTuple<39, Result> + type Expectation = Result, never> + + const inputValues = input() + const result = Result.combine(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 40 elements') { + type Input = CreateTuple<40, Result> + type Expectation = Result, never> + + const inputValues = input() + const result = Result.combine(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 41 elements') { + type Input = CreateTuple<41, Result> + type Expectation = Result, never> + + const inputValues = input() + const result = Result.combine(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 42 elements') { + type Input = CreateTuple<42, Result> + type Expectation = Result, never> + + const inputValues = input() + const result = Result.combine(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 43 elements') { + type Input = CreateTuple<43, Result> + type Expectation = Result, never> + + const inputValues = input() + const result = Result.combine(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 44 elements') { + type Input = CreateTuple<44, Result> + type Expectation = Result, never> + + const inputValues = input() + const result = Result.combine(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 45 elements') { + type Input = CreateTuple<45, Result> + type Expectation = Result, never> + + const inputValues = input() + const result = Result.combine(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 46 elements') { + type Input = CreateTuple<46, Result> + type Expectation = Result, never> + + const inputValues = input() + const result = Result.combine(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 47 elements') { + type Input = CreateTuple<47, Result> + type Expectation = Result, never> + + const inputValues = input() + const result = Result.combine(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 48 elements') { + type Input = CreateTuple<48, Result> + type Expectation = Result, never> + + const inputValues = input() + const result = Result.combine(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 49 elements') { + type Input = CreateTuple<49, Result> + type Expectation = Result, never> + + const inputValues = input() + const result = Result.combine(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + }); }); (function describe(_ = 'combineWithAllErrors') { @@ -352,6 +900,56 @@ import { Transpose } from '../src/result' const assignableToCheck: Expectation = result; const assignablefromCheck: typeof result = assignableToCheck; }); + + (function describe(_ = 'inference on large tuples') { + (function it(_ = 'Should correctly infer the type on tuples with 6 elements') { + type Input = CreateTuple<6, Result> + type Expectation = Result, CreateTuple<6, number>> + + const inputValues = input() + const result = Result.combineWithAllErrors(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 15 elements') { + type Input = CreateTuple<15, Result> + type Expectation = Result, CreateTuple<15, number>> + + const inputValues = input() + const result = Result.combineWithAllErrors(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 30 elements') { + type Input = CreateTuple<30, Result> + type Expectation = Result, CreateTuple<30, number>> + + const inputValues = input() + const result = Result.combineWithAllErrors(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 49 elements') { + type Input = CreateTuple<49 , Result> + type Expectation = Result, CreateTuple<49, number>> + + const inputValues = input() + const result = Result.combineWithAllErrors(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + }); }); }); @@ -726,6 +1324,536 @@ import { Transpose } from '../src/result' const assignableToCheck: Expectation = result; const assignablefromCheck: typeof result = assignableToCheck; }); + + (function describe(_ = 'inference on large tuples') { + (function it(_ = 'Should correctly infer the type on tuples with 6 elements') { + type Input = CreateTuple<6, ResultAsync> + type Expectation = ResultAsync, never> + + const inputValues = input() + const result = ResultAsync.combine(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 7 elements') { + type Input = CreateTuple<7, ResultAsync> + type Expectation = ResultAsync, never> + + const inputValues = input() + const result = ResultAsync.combine(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 8 elements') { + type Input = CreateTuple<8, ResultAsync> + type Expectation = ResultAsync, never> + + const inputValues = input() + const result = ResultAsync.combine(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 9 elements') { + type Input = CreateTuple<9, ResultAsync> + type Expectation = ResultAsync, never> + + const inputValues = input() + const result = ResultAsync.combine(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 10 elements') { + type Input = CreateTuple<10, ResultAsync> + type Expectation = ResultAsync, never> + + const inputValues = input() + const result = ResultAsync.combine(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 11 elements') { + type Input = CreateTuple<11, ResultAsync> + type Expectation = ResultAsync, never> + + const inputValues = input() + const result = ResultAsync.combine(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 12 elements') { + type Input = CreateTuple<12, ResultAsync> + type Expectation = ResultAsync, never> + + const inputValues = input() + const result = ResultAsync.combine(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 13 elements') { + type Input = CreateTuple<13, ResultAsync> + type Expectation = ResultAsync, never> + + const inputValues = input() + const result = ResultAsync.combine(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 14 elements') { + type Input = CreateTuple<14, ResultAsync> + type Expectation = ResultAsync, never> + + const inputValues = input() + const result = ResultAsync.combine(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 15 elements') { + type Input = CreateTuple<15, ResultAsync> + type Expectation = ResultAsync, never> + + const inputValues = input() + const result = ResultAsync.combine(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 16 elements') { + type Input = CreateTuple<16, ResultAsync> + type Expectation = ResultAsync, never> + + const inputValues = input() + const result = ResultAsync.combine(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 17 elements') { + type Input = CreateTuple<17, ResultAsync> + type Expectation = ResultAsync, never> + + const inputValues = input() + const result = ResultAsync.combine(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 18 elements') { + type Input = CreateTuple<18, ResultAsync> + type Expectation = ResultAsync, never> + + const inputValues = input() + const result = ResultAsync.combine(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 19 elements') { + type Input = CreateTuple<19, ResultAsync> + type Expectation = ResultAsync, never> + + const inputValues = input() + const result = ResultAsync.combine(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 20 elements') { + type Input = CreateTuple<20, ResultAsync> + type Expectation = ResultAsync, never> + + const inputValues = input() + const result = ResultAsync.combine(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 21 elements') { + type Input = CreateTuple<21, ResultAsync> + type Expectation = ResultAsync, never> + + const inputValues = input() + const result = ResultAsync.combine(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 22 elements') { + type Input = CreateTuple<22, ResultAsync> + type Expectation = ResultAsync, never> + + const inputValues = input() + const result = ResultAsync.combine(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 23 elements') { + type Input = CreateTuple<23, ResultAsync> + type Expectation = ResultAsync, never> + + const inputValues = input() + const result = ResultAsync.combine(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 24 elements') { + type Input = CreateTuple<24, ResultAsync> + type Expectation = ResultAsync, never> + + const inputValues = input() + const result = ResultAsync.combine(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 25 elements') { + type Input = CreateTuple<25, ResultAsync> + type Expectation = ResultAsync, never> + + const inputValues = input() + const result = ResultAsync.combine(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 26 elements') { + type Input = CreateTuple<26, ResultAsync> + type Expectation = ResultAsync, never> + + const inputValues = input() + const result = ResultAsync.combine(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 27 elements') { + type Input = CreateTuple<27, ResultAsync> + type Expectation = ResultAsync, never> + + const inputValues = input() + const result = ResultAsync.combine(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 28 elements') { + type Input = CreateTuple<28, ResultAsync> + type Expectation = ResultAsync, never> + + const inputValues = input() + const result = ResultAsync.combine(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 29 elements') { + type Input = CreateTuple<29, ResultAsync> + type Expectation = ResultAsync, never> + + const inputValues = input() + const result = ResultAsync.combine(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 30 elements') { + type Input = CreateTuple<30, ResultAsync> + type Expectation = ResultAsync, never> + + const inputValues = input() + const result = ResultAsync.combine(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 31 elements') { + type Input = CreateTuple<31, ResultAsync> + type Expectation = ResultAsync, never> + + const inputValues = input() + const result = ResultAsync.combine(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 32 elements') { + type Input = CreateTuple<32, ResultAsync> + type Expectation = ResultAsync, never> + + const inputValues = input() + const result = ResultAsync.combine(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 33 elements') { + type Input = CreateTuple<33, ResultAsync> + type Expectation = ResultAsync, never> + + const inputValues = input() + const result = ResultAsync.combine(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 34 elements') { + type Input = CreateTuple<34, ResultAsync> + type Expectation = ResultAsync, never> + + const inputValues = input() + const result = ResultAsync.combine(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 35 elements') { + type Input = CreateTuple<35, ResultAsync> + type Expectation = ResultAsync, never> + + const inputValues = input() + const result = ResultAsync.combine(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 36 elements') { + type Input = CreateTuple<36, ResultAsync> + type Expectation = ResultAsync, never> + + const inputValues = input() + const result = ResultAsync.combine(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 37 elements') { + type Input = CreateTuple<37, ResultAsync> + type Expectation = ResultAsync, never> + + const inputValues = input() + const result = ResultAsync.combine(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 38 elements') { + type Input = CreateTuple<38, ResultAsync> + type Expectation = ResultAsync, never> + + const inputValues = input() + const result = ResultAsync.combine(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 39 elements') { + type Input = CreateTuple<39, ResultAsync> + type Expectation = ResultAsync, never> + + const inputValues = input() + const result = ResultAsync.combine(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 40 elements') { + type Input = CreateTuple<40, ResultAsync> + type Expectation = ResultAsync, never> + + const inputValues = input() + const result = ResultAsync.combine(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 41 elements') { + type Input = CreateTuple<41, ResultAsync> + type Expectation = ResultAsync, never> + + const inputValues = input() + const result = ResultAsync.combine(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 42 elements') { + type Input = CreateTuple<42, ResultAsync> + type Expectation = ResultAsync, never> + + const inputValues = input() + const result = ResultAsync.combine(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 43 elements') { + type Input = CreateTuple<43, ResultAsync> + type Expectation = ResultAsync, never> + + const inputValues = input() + const result = ResultAsync.combine(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 44 elements') { + type Input = CreateTuple<44, ResultAsync> + type Expectation = ResultAsync, never> + + const inputValues = input() + const result = ResultAsync.combine(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 45 elements') { + type Input = CreateTuple<45, ResultAsync> + type Expectation = ResultAsync, never> + + const inputValues = input() + const result = ResultAsync.combine(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 46 elements') { + type Input = CreateTuple<46, ResultAsync> + type Expectation = ResultAsync, never> + + const inputValues = input() + const result = ResultAsync.combine(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 47 elements') { + type Input = CreateTuple<47, ResultAsync> + type Expectation = ResultAsync, never> + + const inputValues = input() + const result = ResultAsync.combine(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 48 elements') { + type Input = CreateTuple<48, ResultAsync> + type Expectation = ResultAsync, never> + + const inputValues = input() + const result = ResultAsync.combine(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 49 elements') { + type Input = CreateTuple<49, ResultAsync> + type Expectation = ResultAsync, never> + + const inputValues = input() + const result = ResultAsync.combine(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + }); }); (function describe(_ = 'combineWithAllErrors') { @@ -776,6 +1904,59 @@ import { Transpose } from '../src/result' const assignableToCheck: Expectation = result; const assignablefromCheck: typeof result = assignableToCheck; }); + + (function describe(_ = 'inference on large tuples') { + (function it(_ = 'Should correctly infer the type on tuples with 6 elements') { + type Input = CreateTuple<6, ResultAsync> + type Expectation = ResultAsync, CreateTuple<6, number>> + + const inputValues = input() + const result = ResultAsync.combineWithAllErrors(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 15 elements') { + type Input = CreateTuple<15, ResultAsync> + type Expectation = ResultAsync, CreateTuple<15, number>> + + const inputValues = input() + const result = ResultAsync.combineWithAllErrors(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 30 elements') { + type Input = CreateTuple<30, ResultAsync> + type Expectation = ResultAsync, CreateTuple<30, number>> + + const inputValues = input() + const result = ResultAsync.combineWithAllErrors(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + + (function it(_ = 'Should correctly infer the type on tuples with 49 elements') { + type Input = CreateTuple<49 , ResultAsync> + type Expectation = ResultAsync, CreateTuple<49, number>> + + const inputValues = input() + const result = ResultAsync.combineWithAllErrors(inputValues) + + Test.checks([ + Test.check(), + ]) + }); + }); + + + }); }); @@ -832,3 +2013,6 @@ declare function transpose< >(input: A): Transpose<[ ...A ]>; //#endregion + +// create dummy values with a desired type +const input = (): T => 123 as any diff --git a/tsconfig.json b/tsconfig.json index 0bac9427..31f46999 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,5 +1,6 @@ { "compilerOptions": { + "target": "es2015", "module": "ES2015", "noImplicitAny": true, "sourceMap": false, @@ -25,4 +26,4 @@ "node_modules", "**/*.spec.ts" ] -} \ No newline at end of file +}