Skip to content

Commit

Permalink
remove useless constraint
Browse files Browse the repository at this point in the history
  • Loading branch information
gcanti committed May 21, 2020
1 parent 77ea096 commit c59dc2f
Show file tree
Hide file tree
Showing 17 changed files with 24 additions and 42 deletions.
2 changes: 1 addition & 1 deletion docs/modules/Decoder.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ Added in v2.2.0
```ts
export declare function sum<T extends string>(
tag: T
): <A>(members: { [K in keyof A]: Decoder<A[K] & Record<T, K>> }) => Decoder<A[keyof A]>
): <A>(members: { [K in keyof A]: Decoder<A[K]> }) => Decoder<A[keyof A]>
```

Added in v2.2.0
Expand Down
4 changes: 1 addition & 3 deletions docs/modules/Eq.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,7 @@ Added in v2.2.2
**Signature**

```ts
export declare function sum<T extends string>(
tag: T
): <A>(members: { [K in keyof A]: Eq<A[K] & Record<T, K>> }) => Eq<A[keyof A]>
export declare function sum<T extends string>(tag: T): <A>(members: { [K in keyof A]: Eq<A[K]> }) => Eq<A[keyof A]>
```

Added in v2.2.2
Expand Down
2 changes: 1 addition & 1 deletion docs/modules/Guard.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ Added in v2.2.0
```ts
export declare function sum<T extends string>(
tag: T
): <A>(members: { [K in keyof A]: Guard<A[K] & Record<T, K>> }) => Guard<A[keyof A]>
): <A>(members: { [K in keyof A]: Guard<A[K]> }) => Guard<A[keyof A]>
```

Added in v2.2.0
Expand Down
2 changes: 1 addition & 1 deletion docs/modules/JsonCodec.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ Added in v2.2.3
```ts
export declare const sum: <T extends string>(
tag: T
) => <A>(members: { [K in keyof A]: JsonCodec<A[K] & Record<T, K>> }) => JsonCodec<A[keyof A]>
) => <A>(members: { [K in keyof A]: JsonCodec<A[K]> }) => JsonCodec<A[keyof A]>
```
Added in v2.2.3
Expand Down
2 changes: 1 addition & 1 deletion docs/modules/JsonEncoder.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ Added in v2.2.3
```ts
export declare const sum: <T extends string>(
tag: T
) => <A>(members: { [K in keyof A]: JsonEncoder<A[K] & Record<T, K>> }) => JsonEncoder<A[keyof A]>
) => <A>(members: { [K in keyof A]: JsonEncoder<A[K]> }) => JsonEncoder<A[keyof A]>
```
Added in v2.2.3
Expand Down
8 changes: 2 additions & 6 deletions docs/modules/Schemable.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ export interface Schemable<S> {
readonly array: <A>(items: HKT<S, A>) => HKT<S, Array<A>>
readonly tuple: <A extends ReadonlyArray<unknown>>(...components: { [K in keyof A]: HKT<S, A[K]> }) => HKT<S, A>
readonly intersection: <A, B>(left: HKT<S, A>, right: HKT<S, B>) => HKT<S, A & B>
readonly sum: <T extends string>(
tag: T
) => <A>(members: { [K in keyof A]: HKT<S, A[K] & Record<T, K>> }) => HKT<S, A[keyof A]>
readonly sum: <T extends string>(tag: T) => <A>(members: { [K in keyof A]: HKT<S, A[K]> }) => HKT<S, A[keyof A]>
readonly lazy: <A>(id: string, f: () => HKT<S, A>) => HKT<S, A>
}
```
Expand All @@ -70,9 +68,7 @@ export interface Schemable1<S extends URIS> {
readonly array: <A>(items: Kind<S, A>) => Kind<S, Array<A>>
readonly tuple: <A extends ReadonlyArray<unknown>>(...components: { [K in keyof A]: Kind<S, A[K]> }) => Kind<S, A>
readonly intersection: <A, B>(left: Kind<S, A>, right: Kind<S, B>) => Kind<S, A & B>
readonly sum: <T extends string>(
tag: T
) => <A>(members: { [K in keyof A]: Kind<S, A[K] & Record<T, K>> }) => Kind<S, A[keyof A]>
readonly sum: <T extends string>(tag: T) => <A>(members: { [K in keyof A]: Kind<S, A[K]> }) => Kind<S, A[keyof A]>
readonly lazy: <A>(id: string, f: () => Kind<S, A>) => Kind<S, A>
}
```
Expand Down
4 changes: 1 addition & 3 deletions docs/modules/Type.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,7 @@ Added in v2.2.3
**Signature**

```ts
export declare function sum<T extends string>(
_tag: T
): <A>(members: { [K in keyof A]: Type<A[K] & Record<T, K>> }) => Type<A[keyof A]>
export declare function sum<T extends string>(_tag: T): <A>(members: { [K in keyof A]: Type<A[K]> }) => Type<A[keyof A]>
```

Added in v2.2.3
Expand Down
2 changes: 2 additions & 0 deletions dtslint/ts3.5/Econder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ const sum = E.sum('_tag')
// $ExpectType Encoder<{ _tag: "A"; a: string; } | { _tag: "B"; b: number; }, { _tag: "A"; a: number; } | { _tag: "B"; b: boolean; }>
sum({ A: S1, B: S2 })

const S3 = E.type({ _tag: E.id<'C'>(), c: E.id<string>() })

//
// lazy
//
Expand Down
4 changes: 1 addition & 3 deletions src/Decoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,9 +386,7 @@ export function lazy<A>(id: string, f: () => Decoder<A>): Decoder<A> {
/**
* @since 2.2.0
*/
export function sum<T extends string>(
tag: T
): <A>(members: { [K in keyof A]: Decoder<A[K] & Record<T, K>> }) => Decoder<A[keyof A]> {
export function sum<T extends string>(tag: T): <A>(members: { [K in keyof A]: Decoder<A[K]> }) => Decoder<A[keyof A]> {
return (members) => {
const keys = Object.keys(members)
if (keys.length === 0) {
Expand Down
4 changes: 2 additions & 2 deletions src/Encoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ export function intersection<O, A, P, B>(left: Encoder<O, A>, right: Encoder<P,
export function sum<T extends string>(
tag: T
): <M extends Record<string, Encoder<any, any>>>(members: M) => Encoder<OutputOf<M[keyof M]>, TypeOf<M[keyof M]>> {
return (members: Record<string, Encoder<any, any>>) => {
return (members) => {
return {
encode: (a: Record<string, any>) => members[a[tag]].encode(a)
encode: (a) => members[a[tag]].encode(a)
}
}
}
Expand Down
4 changes: 1 addition & 3 deletions src/Eq.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,7 @@ export function intersection<A, B>(left: Eq<A>, right: Eq<B>): Eq<A & B> {
/**
* @since 2.2.2
*/
export function sum<T extends string>(
tag: T
): <A>(members: { [K in keyof A]: Eq<A[K] & Record<T, K>> }) => Eq<A[keyof A]> {
export function sum<T extends string>(tag: T): <A>(members: { [K in keyof A]: Eq<A[K]> }) => Eq<A[keyof A]> {
return (members: Record<string, Eq<any>>) => {
return {
equals: (x: Record<string, any>, y: Record<string, any>) => {
Expand Down
10 changes: 4 additions & 6 deletions src/Guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,14 +182,12 @@ export function union<A extends ReadonlyArray<unknown>>(...members: { [K in keyo
/**
* @since 2.2.0
*/
export function sum<T extends string>(
tag: T
): <A>(members: { [K in keyof A]: Guard<A[K] & Record<T, K>> }) => Guard<A[keyof A]> {
return <A>(members: { [K in keyof A]: Guard<A[K] & Record<T, K>> }) =>
refinement(UnknownRecord, (r): r is { [K in keyof A]: A[K] & Record<T, K> }[keyof A] => {
export function sum<T extends string>(tag: T): <A>(members: { [K in keyof A]: Guard<A[K]> }) => Guard<A[keyof A]> {
return (members: Record<string, Guard<unknown>>) =>
refinement(UnknownRecord, (r): r is any => {
const v = r[tag]
if (string.is(v) && v in members) {
return (members as any)[v].is(r)
return members[v].is(r)
}
return false
})
Expand Down
2 changes: 1 addition & 1 deletion src/JsonCodec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export const intersection: <A, B>(left: JsonCodec<A>, right: JsonCodec<B>) => Js
*/
export const sum: <T extends string>(
tag: T
) => <A>(members: { [K in keyof A]: JsonCodec<A[K] & Record<T, K>> }) => JsonCodec<A[keyof A]> = C.sum as any
) => <A>(members: { [K in keyof A]: JsonCodec<A[K]> }) => JsonCodec<A[keyof A]> = C.sum as any

/**
* @since 2.2.3
Expand Down
2 changes: 1 addition & 1 deletion src/JsonEncoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export const intersection: <A, B>(left: JsonEncoder<A>, right: JsonEncoder<B>) =
*/
export const sum: <T extends string>(
tag: T
) => <A>(members: { [K in keyof A]: JsonEncoder<A[K] & Record<T, K>> }) => JsonEncoder<A[keyof A]> = E.sum as any
) => <A>(members: { [K in keyof A]: JsonEncoder<A[K]> }) => JsonEncoder<A[keyof A]> = E.sum as any

/**
* @since 2.2.3
Expand Down
8 changes: 2 additions & 6 deletions src/Schemable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ export interface Schemable<S> {
readonly array: <A>(items: HKT<S, A>) => HKT<S, Array<A>>
readonly tuple: <A extends ReadonlyArray<unknown>>(...components: { [K in keyof A]: HKT<S, A[K]> }) => HKT<S, A>
readonly intersection: <A, B>(left: HKT<S, A>, right: HKT<S, B>) => HKT<S, A & B>
readonly sum: <T extends string>(
tag: T
) => <A>(members: { [K in keyof A]: HKT<S, A[K] & Record<T, K>> }) => HKT<S, A[keyof A]>
readonly sum: <T extends string>(tag: T) => <A>(members: { [K in keyof A]: HKT<S, A[K]> }) => HKT<S, A[keyof A]>
readonly lazy: <A>(id: string, f: () => HKT<S, A>) => HKT<S, A>
}

Expand All @@ -46,9 +44,7 @@ export interface Schemable1<S extends URIS> {
readonly array: <A>(items: Kind<S, A>) => Kind<S, Array<A>>
readonly tuple: <A extends ReadonlyArray<unknown>>(...components: { [K in keyof A]: Kind<S, A[K]> }) => Kind<S, A>
readonly intersection: <A, B>(left: Kind<S, A>, right: Kind<S, B>) => Kind<S, A & B>
readonly sum: <T extends string>(
tag: T
) => <A>(members: { [K in keyof A]: Kind<S, A[K] & Record<T, K>> }) => Kind<S, A[keyof A]>
readonly sum: <T extends string>(tag: T) => <A>(members: { [K in keyof A]: Kind<S, A[K]> }) => Kind<S, A[keyof A]>
readonly lazy: <A>(id: string, f: () => Kind<S, A>) => Kind<S, A>
}

Expand Down
4 changes: 1 addition & 3 deletions src/Type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,7 @@ export function lazy<A>(id: string, f: () => Type<A>): Type<A> {
/**
* @since 2.2.3
*/
export function sum<T extends string>(
_tag: T
): <A>(members: { [K in keyof A]: Type<A[K] & Record<T, K>> }) => Type<A[keyof A]> {
export function sum<T extends string>(_tag: T): <A>(members: { [K in keyof A]: Type<A[K]> }) => Type<A[keyof A]> {
return (members) => t.union(Object.values(members) as any)
}

Expand Down
2 changes: 1 addition & 1 deletion test/Arbitrary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export function intersection<A, B>(left: Arbitrary<A>, right: Arbitrary<B>): Arb

export function sum<T extends string>(
_tag: T
): <A>(members: { [K in keyof A]: Arbitrary<A[K] & Record<T, K>> }) => Arbitrary<A[keyof A]> {
): <A>(members: { [K in keyof A]: Arbitrary<A[K]> }) => Arbitrary<A[keyof A]> {
return (members: Record<string, Arbitrary<any>>) => fc.oneof(...Object.keys(members).map((k) => members[k]))
}

Expand Down

0 comments on commit c59dc2f

Please sign in to comment.