diff --git a/docs/modules/index.ts.md b/docs/modules/index.ts.md index d1dbde41f..cc26efb20 100644 --- a/docs/modules/index.ts.md +++ b/docs/modules/index.ts.md @@ -666,31 +666,33 @@ Added in v1.5.3 **Signature** ```ts -export interface TupleC]> +export interface TupleC]> extends TupleType< CS, - CS extends { length: 1 } + CS extends { readonly length: 1 } ? [TypeOf] - : CS extends { length: 2 } + : CS extends { readonly length: 2 } ? [TypeOf, TypeOf] - : CS extends { length: 3 } + : CS extends { readonly length: 3 } ? [TypeOf, TypeOf, TypeOf] - : CS extends { length: 4 } + : CS extends { readonly length: 4 } ? [TypeOf, TypeOf, TypeOf, TypeOf] - : CS extends { length: 5 } + : CS extends { readonly length: 5 } ? [TypeOf, TypeOf, TypeOf, TypeOf, TypeOf] : unknown, - CS extends { length: 1 } + // : { [K in keyof CS]: CS[K] extends Mixed ? TypeOf : unknown }, + CS extends { readonly length: 1 } ? [OutputOf] - : CS extends { length: 2 } + : CS extends { readonly length: 2 } ? [OutputOf, OutputOf] - : CS extends { length: 3 } + : CS extends { readonly length: 3 } ? [OutputOf, OutputOf, OutputOf] - : CS extends { length: 4 } + : CS extends { readonly length: 4 } ? [OutputOf, OutputOf, OutputOf, OutputOf] - : CS extends { length: 5 } + : CS extends { readonly length: 5 } ? [OutputOf, OutputOf, OutputOf, OutputOf, OutputOf] : unknown, + // : { [K in keyof CS]: CS[K] extends Mixed ? OutputOf : unknown }, unknown > {} ``` @@ -2259,20 +2261,10 @@ Added in v1.0.0 **Signature** ```ts -export declare function tuple( - codecs: [A, B, C, D, E], - name?: string -): TupleC<[A, B, C, D, E]> -export declare function tuple( - codecs: [A, B, C, D], - name?: string -): TupleC<[A, B, C, D]> -export declare function tuple( - codecs: [A, B, C], - name?: string -): TupleC<[A, B, C]> -export declare function tuple(codecs: [A, B], name?: string): TupleC<[A, B]> -export declare function tuple(codecs: [A], name?: string): TupleC<[A]> +export declare function tuple]>( + codecs: CS, + name: string = `[${codecs.map((type) => type.name).join(', ')}]` +): TupleC ``` Added in v1.0.0 diff --git a/dtslint/after3.8/index.d.ts b/dtslint/after3.8/index.d.ts new file mode 100644 index 000000000..45362d6a6 --- /dev/null +++ b/dtslint/after3.8/index.d.ts @@ -0,0 +1 @@ +// TypeScript Version: 3.8 diff --git a/dtslint/ts3.5/index.d.ts b/dtslint/after3.8/ts3.8/index.d.ts similarity index 100% rename from dtslint/ts3.5/index.d.ts rename to dtslint/after3.8/ts3.8/index.d.ts diff --git a/dtslint/after3.8/ts3.8/index.ts b/dtslint/after3.8/ts3.8/index.ts new file mode 100644 index 000000000..243c74455 --- /dev/null +++ b/dtslint/after3.8/ts3.8/index.ts @@ -0,0 +1,9 @@ +import * as t from '../../../src' + +const Tuple8 = t.tuple([t.string, t.string, t.string, t.string, t.string, t.string]) +type Tuple8TypeTest = t.TypeOf // $ExpectType [string, string, string, string, string, string] +type Tuple8OutputTest = t.OutputOf // $ExpectType [string, string, string, string, string, string] + +const Tuple9 = t.tuple([t.string, t.string, t.boolean, t.string, t.string, t.string, t.string]) +type Tuple9TypeTest = t.TypeOf // $ExpectType [string, string, boolean, string, string, string, string] +type Tuple9OutputTest = t.OutputOf // $ExpectType [string, string, boolean, string, string, string, string] diff --git a/dtslint/ts3.5/tsconfig.json b/dtslint/after3.8/ts3.8/tsconfig.json similarity index 100% rename from dtslint/ts3.5/tsconfig.json rename to dtslint/after3.8/ts3.8/tsconfig.json diff --git a/dtslint/ts3.5/tslint.json b/dtslint/after3.8/ts3.8/tslint.json similarity index 100% rename from dtslint/ts3.5/tslint.json rename to dtslint/after3.8/ts3.8/tslint.json diff --git a/dtslint/index.d.ts b/dtslint/base/index.d.ts similarity index 100% rename from dtslint/index.d.ts rename to dtslint/base/index.d.ts diff --git a/dtslint/base/ts3.5/index.d.ts b/dtslint/base/ts3.5/index.d.ts new file mode 100644 index 000000000..e69de29bb diff --git a/dtslint/ts3.5/index.ts b/dtslint/base/ts3.5/index.ts similarity index 99% rename from dtslint/ts3.5/index.ts rename to dtslint/base/ts3.5/index.ts index 69c1cbc19..3f15af6a7 100644 --- a/dtslint/ts3.5/index.ts +++ b/dtslint/base/ts3.5/index.ts @@ -1,4 +1,4 @@ -import * as t from '../../src' +import * as t from '../../../src' import { either } from 'fp-ts/lib/Either' // @@ -239,9 +239,6 @@ const Tuple7 = t.tuple([t.string, t.number, t.boolean, t.null, t.undefined]) // type Tuple7TypeTest = t.TypeOf // $ExpectType [string, number, boolean, null, undefined] type Tuple7OutputTest = t.OutputOf // $ExpectType [string, number, boolean, null, undefined] -// $ExpectError -const Tuple8 = t.tuple([t.string, t.string, t.string, t.string, t.string, t.string]) - // // partial // diff --git a/dtslint/base/ts3.5/tsconfig.json b/dtslint/base/ts3.5/tsconfig.json new file mode 100644 index 000000000..a83515bca --- /dev/null +++ b/dtslint/base/ts3.5/tsconfig.json @@ -0,0 +1,16 @@ +{ + "compilerOptions": { + "noEmit": true, + "strict": true, + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "noImplicitReturns": false, + "noUnusedLocals": false, + "noUnusedParameters": true, + "noFallthroughCasesInSwitch": true, + "target": "es5", + "lib": ["es2015"] + } +} diff --git a/dtslint/base/ts3.5/tslint.json b/dtslint/base/ts3.5/tslint.json new file mode 100644 index 000000000..9ce37507e --- /dev/null +++ b/dtslint/base/ts3.5/tslint.json @@ -0,0 +1,19 @@ +{ + "extends": "dtslint/dtslint.json", + "rules": { + "semicolon": false, + "array-type": false, + "no-unnecessary-generics": false, + "member-access": false, + "no-empty-interface": false, + "no-arg": false, + "no-object-literal-type-assertion": false, + "no-unnecessary-class": false, + "radix": false, + "no-angle-bracket-type-assertion": false, + "object-literal-shorthand": false, + "prefer-object-spread": false, + "whitespace": false, + "use-default-type-parameter": false + } +} diff --git a/package.json b/package.json index 36c5d24cb..12c7a2ade 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ "build": "npm run clean && tsc && tsc -p tsconfig.es6.json && npm run import-path-rewrite", "prepublish": "npm run build", "perf": "ts-node perf/index", - "dtslint": "dtslint dtslint", + "dtslint": "dtslint dtslint/base && dtslint dtslint/after3.8", "declaration": "tsc -p declaration/tsconfig.json", "mocha": "TS_NODE_CACHE=false mocha -r ts-node/register test/*.ts", "doctoc": "doctoc README.md", diff --git a/src/index.ts b/src/index.ts index 0af62149d..ea6bcbbb5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -812,7 +812,7 @@ const getNameFromProps = (props: Props): string => .map((k) => `${k}: ${props[k].name}`) .join(', ') -const useIdentity = (codecs: Array): boolean => { +const useIdentity = (codecs: readonly Any[]): boolean => { for (let i = 0; i < codecs.length; i++) { if (codecs[i].encode !== identity) { return false @@ -1431,7 +1431,7 @@ export function intersection]>( /** * @since 1.0.0 */ -export class TupleType, A = any, O = A, I = unknown> extends Type { +export class TupleType extends Type { /** * @since 1.0.0 */ @@ -1450,52 +1450,38 @@ export class TupleType, A = any, O = A, I = unknown> exten /** * @since 1.5.3 */ -export interface TupleC]> +export interface TupleC]> extends TupleType< CS, - CS extends { length: 1 } + CS extends { readonly length: 1 } ? [TypeOf] - : CS extends { length: 2 } + : CS extends { readonly length: 2 } ? [TypeOf, TypeOf] - : CS extends { length: 3 } + : CS extends { readonly length: 3 } ? [TypeOf, TypeOf, TypeOf] - : CS extends { length: 4 } + : CS extends { readonly length: 4 } ? [TypeOf, TypeOf, TypeOf, TypeOf] - : CS extends { length: 5 } + : CS extends { readonly length: 5 } ? [TypeOf, TypeOf, TypeOf, TypeOf, TypeOf] - : unknown, - CS extends { length: 1 } + : { [K in keyof CS]: CS[K] extends Mixed ? TypeOf : unknown }, + CS extends { readonly length: 1 } ? [OutputOf] - : CS extends { length: 2 } + : CS extends { readonly length: 2 } ? [OutputOf, OutputOf] - : CS extends { length: 3 } + : CS extends { readonly length: 3 } ? [OutputOf, OutputOf, OutputOf] - : CS extends { length: 4 } + : CS extends { readonly length: 4 } ? [OutputOf, OutputOf, OutputOf, OutputOf] - : CS extends { length: 5 } + : CS extends { readonly length: 5 } ? [OutputOf, OutputOf, OutputOf, OutputOf, OutputOf] - : unknown, + : { [K in keyof CS]: CS[K] extends Mixed ? OutputOf : unknown }, unknown > {} /** * @since 1.0.0 */ -export function tuple( - codecs: [A, B, C, D, E], - name?: string -): TupleC<[A, B, C, D, E]> -export function tuple( - codecs: [A, B, C, D], - name?: string -): TupleC<[A, B, C, D]> -export function tuple( - codecs: [A, B, C], - name?: string -): TupleC<[A, B, C]> -export function tuple(codecs: [A, B], name?: string): TupleC<[A, B]> -export function tuple(codecs: [A], name?: string): TupleC<[A]> -export function tuple]>( +export function tuple]>( codecs: CS, name: string = `[${codecs.map((type) => type.name).join(', ')}]` ): TupleC {