Skip to content

Commit

Permalink
rebase master
Browse files Browse the repository at this point in the history
  • Loading branch information
gcanti committed Feb 6, 2018
1 parent f2b4f57 commit 46232c4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
6 changes: 1 addition & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1076,11 +1076,7 @@ export const taggedUnion = <Tag extends string, RTS extends Array<Tagged<Tag>>>(
),
types.every(type => type.serialize === identity)
? identity
: a => {
const tagValue = a[tag] as any
const type = types[tagValue2Index[tagValue]]
return type.serialize(a)
},
: a => types[tagValue2Index[a[tag] as any]].serialize(a),
types
)
}
Expand Down
6 changes: 3 additions & 3 deletions typings-checker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const Rec1 = t.recursion<RecT1>('T', Self =>
items: t.array(Self)
})
)
// $ExpectError Type 'InterfaceOf<{ type: LiteralType<"a">; items: ArrayType<Type<mixed, string>, string[]>; }>' is not assignable to type 'string'
// $ExpectError Argument of type '(Self: Type<string, string, mixed>) => InterfaceType<{ type: LiteralType<"a">; items: ArrayType<T...' is not assignable to parameter of type '(self: Type<string, string, mixed>) => Type<string, string, mixed>'
const Rec2 = t.recursion<string>('T', Self =>
t.interface({
type: t.literal('a'),
Expand Down Expand Up @@ -163,7 +163,7 @@ const x25: TypeOf<typeof RO1> = { name: 1 }
//

const ROA1 = t.readonlyArray(t.number)
// $ExpectError Type 'string' is not assignable to type 'number'
// $ExpectError Type 'string[]' is not assignable to type 'ReadonlyArray<number>'
const x26: TypeOf<typeof ROA1> = ['s']
const x27: TypeOf<typeof ROA1> = [1]
// $ExpectError Index signature in type 'ReadonlyArray<number>' only permits reading
Expand Down Expand Up @@ -305,7 +305,7 @@ f(Rec) // OK!
// tagged union
//
const TU1 = t.taggedUnion('type', [t.type({ type: t.literal('a') }), t.type({ type: t.literal('b') })])
// $ExpectError Type 'true' is not assignable to type 'InterfaceOf<{ type: LiteralType<"a">; }> | InterfaceOf<{ type: LiteralType<"b">; }>'
// $ExpectError Type 'true' is not assignable to type 'TypeOfProps<{ type: LiteralType<"a">; }> | TypeOfProps<{ type: LiteralType<"b">; }>'
const x36: TypeOf<typeof TU1> = true
const x37: TypeOf<typeof TU1> = { type: 'a' }
const x38: TypeOf<typeof TU1> = { type: 'b' }

0 comments on commit 46232c4

Please sign in to comment.