Skip to content

Commit

Permalink
Deprecation: deprecate Compact type
Browse files Browse the repository at this point in the history
  • Loading branch information
gcanti committed Jan 8, 2019
1 parent ff464dd commit 3900b13
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 23 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**
Expand Down
2 changes: 1 addition & 1 deletion dtslint/index.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
// TypeScript Version: 2.7
// TypeScript Version: 3.0
36 changes: 27 additions & 9 deletions dtslint/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,37 @@ type Assert10 = t.TypeOf<typeof U1> // $ExpectType string | number
//

const IN1 = t.intersection([t.string, t.number])
type Assert11 = t.TypeOf<typeof IN1> // $ExpectType Compact<string & number>
type Assert11 = t.TypeOf<typeof IN1> // $ExpectType string & number
const IN2 = t.intersection([t.interface({ a: t.number }), t.interface({ b: t.string })])
type Assert12 = t.TypeOf<typeof IN2> // $ExpectType Compact<TypeOfProps<{ a: NumberType; }> & TypeOfProps<{ b: StringType; }>>
type Assert12 = t.TypeOf<typeof IN2> // $ExpectType TypeOfProps<{ a: NumberType; }> & TypeOfProps<{ b: StringType; }>
// $ExpectError
const x17: t.TypeOf<typeof IN2> = { a: 1 }
const x18: t.TypeOf<typeof IN2> = { a: 1, b: 's' }

declare function testIntersectionInput<T>(x: t.Type<Record<keyof T, string>, any, unknown>): void
declare function testIntersectionOuput<T>(x: t.Type<any, Record<keyof T, string>, 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<typeof IntersectionWithPrimitive> // $ExpectType number & TypeOfProps<{ a: LiteralType<"a">; }>

//
// tuple
//
Expand Down Expand Up @@ -397,7 +421,7 @@ export function interfaceWithOptionals<RequiredProps extends t.Props, OptionalPr
t.InterfaceType<RequiredProps, t.TypeOfProps<RequiredProps>>,
t.PartialType<OptionalProps, t.TypeOfPartialProps<OptionalProps>>
],
t.Compact<t.TypeOfProps<RequiredProps> & t.TypeOfPartialProps<OptionalProps>>
t.TypeOfProps<RequiredProps> & t.TypeOfPartialProps<OptionalProps>
> {
return t.intersection([t.interface(required), t.partial(optional)], name)
}
Expand Down Expand Up @@ -451,9 +475,3 @@ declare function withValidation<L, A>(
declare const fa: TaskEither<string, void>

withValidation(t.void, () => 'validation error', fa)

// $ExpectError
const T: t.Type<any, { [k: string]: string }> = t.intersection([
t.interface({ a: t.string }),
t.interface({ b: t.number })
]);
3 changes: 2 additions & 1 deletion dtslint/tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"extends": "dtslint/dtslint.json",
"rules": {
"semicolon": false,
"array-type": false
"array-type": false,
"no-unnecessary-generics": false
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
18 changes: 7 additions & 11 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1044,6 +1044,7 @@ export class IntersectionType<RTS extends Array<Any>, A = any, O = A, I = mixed>
/**
* used in `intersection` as a workaround for #234
* @since 1.4.2
* @deprecated
*/
export type Compact<A> = { [K in keyof A]: A[K] }

Expand All @@ -1055,32 +1056,27 @@ export function intersection<A extends Mixed, B extends Mixed, C extends Mixed,
name?: string
): IntersectionType<
[A, B, C, D, E],
Compact<TypeOf<A> & TypeOf<B> & TypeOf<C> & TypeOf<D> & TypeOf<E>>,
Compact<OutputOf<A> & OutputOf<B> & OutputOf<C> & OutputOf<D> & OutputOf<E>>,
TypeOf<A> & TypeOf<B> & TypeOf<C> & TypeOf<D> & TypeOf<E>,
OutputOf<A> & OutputOf<B> & OutputOf<C> & OutputOf<D> & OutputOf<E>,
mixed
>
export function intersection<A extends Mixed, B extends Mixed, C extends Mixed, D extends Mixed>(
types: [A, B, C, D],
name?: string
): IntersectionType<
[A, B, C, D],
Compact<TypeOf<A> & TypeOf<B> & TypeOf<C> & TypeOf<D>>,
Compact<OutputOf<A> & OutputOf<B> & OutputOf<C> & OutputOf<D>>,
TypeOf<A> & TypeOf<B> & TypeOf<C> & TypeOf<D>,
OutputOf<A> & OutputOf<B> & OutputOf<C> & OutputOf<D>,
mixed
>
export function intersection<A extends Mixed, B extends Mixed, C extends Mixed>(
types: [A, B, C],
name?: string
): IntersectionType<
[A, B, C],
Compact<TypeOf<A> & TypeOf<B> & TypeOf<C>>,
Compact<OutputOf<A> & OutputOf<B> & OutputOf<C>>,
mixed
>
): IntersectionType<[A, B, C], TypeOf<A> & TypeOf<B> & TypeOf<C>, OutputOf<A> & OutputOf<B> & OutputOf<C>, mixed>
export function intersection<A extends Mixed, B extends Mixed>(
types: [A, B],
name?: string
): IntersectionType<[A, B], Compact<TypeOf<A> & TypeOf<B>>, Compact<OutputOf<A> & OutputOf<B>>, mixed>
): IntersectionType<[A, B], TypeOf<A> & TypeOf<B>, OutputOf<A> & OutputOf<B>, mixed>
export function intersection<A extends Mixed>(
types: [A],
name?: string
Expand Down

0 comments on commit 3900b13

Please sign in to comment.