diff --git a/CHANGELOG.md b/CHANGELOG.md index ac9ff0c5c..f02b54c8d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,11 @@ **Note**: Gaps between patch versions are faulty/broken releases. **Note**: A feature tagged as Experimental is in a high state of flux, you're at risk of it changing without notice. +# 1.5.2 + +- **Deprecation** + - deprecate `Compact` type (@gcanti) + # 1.5.1 - **Polish** diff --git a/dtslint/index.d.ts b/dtslint/index.d.ts index 54d90168a..005ae20be 100644 --- a/dtslint/index.d.ts +++ b/dtslint/index.d.ts @@ -1 +1 @@ -// TypeScript Version: 2.7 +// TypeScript Version: 3.0 diff --git a/dtslint/index.ts b/dtslint/index.ts index 977483b2e..260b35f35 100644 --- a/dtslint/index.ts +++ b/dtslint/index.ts @@ -106,13 +106,37 @@ type Assert10 = t.TypeOf // $ExpectType string | number // const IN1 = t.intersection([t.string, t.number]) -type Assert11 = t.TypeOf // $ExpectType Compact +type Assert11 = t.TypeOf // $ExpectType string & number const IN2 = t.intersection([t.interface({ a: t.number }), t.interface({ b: t.string })]) -type Assert12 = t.TypeOf // $ExpectType Compact & TypeOfProps<{ b: StringType; }>> +type Assert12 = t.TypeOf // $ExpectType TypeOfProps<{ a: NumberType; }> & TypeOfProps<{ b: StringType; }> // $ExpectError const x17: t.TypeOf = { a: 1 } const x18: t.TypeOf = { a: 1, b: 's' } +declare function testIntersectionInput(x: t.Type, any, unknown>): void +declare function testIntersectionOuput(x: t.Type, unknown>): void +const QueryString = t.intersection([ + t.interface({ + a: t.string + }), + t.interface({ + b: t.number + }) +]) +// $ExpectError +testIntersectionInput(QueryString) +// $ExpectError +testIntersectionOuput(QueryString) + +const IntersectionWithPrimitive = t.intersection([ + t.number, + t.type({ + a: t.literal('a') + }) +]) + +type IntersectionWithPrimitive = t.TypeOf // $ExpectType number & TypeOfProps<{ a: LiteralType<"a">; }> + // // tuple // @@ -397,7 +421,7 @@ export function interfaceWithOptionals>, t.PartialType> ], - t.Compact & t.TypeOfPartialProps> + t.TypeOfProps & t.TypeOfPartialProps > { return t.intersection([t.interface(required), t.partial(optional)], name) } @@ -451,9 +475,3 @@ declare function withValidation( declare const fa: TaskEither withValidation(t.void, () => 'validation error', fa) - -// $ExpectError -const T: t.Type = t.intersection([ - t.interface({ a: t.string }), - t.interface({ b: t.number }) -]); diff --git a/dtslint/tslint.json b/dtslint/tslint.json index dbd333d44..8ae797927 100644 --- a/dtslint/tslint.json +++ b/dtslint/tslint.json @@ -2,6 +2,7 @@ "extends": "dtslint/dtslint.json", "rules": { "semicolon": false, - "array-type": false + "array-type": false, + "no-unnecessary-generics": false } } diff --git a/package.json b/package.json index be790057f..6396b3d0d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "io-ts", - "version": "1.5.1", + "version": "1.5.2", "description": "TypeScript compatible runtime type system for IO validation", "files": [ "lib" diff --git a/src/index.ts b/src/index.ts index b3730dd3b..1578b20fd 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1044,6 +1044,7 @@ export class IntersectionType, A = any, O = A, I = mixed> /** * used in `intersection` as a workaround for #234 * @since 1.4.2 + * @deprecated */ export type Compact = { [K in keyof A]: A[K] } @@ -1055,8 +1056,8 @@ export function intersection & TypeOf & TypeOf & TypeOf & TypeOf>, - Compact & OutputOf & OutputOf & OutputOf & OutputOf>, + TypeOf & TypeOf & TypeOf & TypeOf & TypeOf, + OutputOf & OutputOf & OutputOf & OutputOf & OutputOf, mixed > export function intersection( @@ -1064,23 +1065,18 @@ export function intersection & TypeOf & TypeOf & TypeOf>, - Compact & OutputOf & OutputOf & OutputOf>, + TypeOf & TypeOf & TypeOf & TypeOf, + OutputOf & OutputOf & OutputOf & OutputOf, mixed > export function intersection( types: [A, B, C], name?: string -): IntersectionType< - [A, B, C], - Compact & TypeOf & TypeOf>, - Compact & OutputOf & OutputOf>, - mixed -> +): IntersectionType<[A, B, C], TypeOf & TypeOf & TypeOf, OutputOf & OutputOf & OutputOf, mixed> export function intersection( types: [A, B], name?: string -): IntersectionType<[A, B], Compact & TypeOf>, Compact & OutputOf>, mixed> +): IntersectionType<[A, B], TypeOf & TypeOf, OutputOf & OutputOf, mixed> export function intersection( types: [A], name?: string