From 7b4525c167dc7ea8eed111f158552778b728b284 Mon Sep 17 00:00:00 2001 From: gcanti Date: Mon, 12 Feb 2018 12:36:52 +0100 Subject: [PATCH] make derived type more readable --- src/index.ts | 8 ++++---- typings-checker/index.ts | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/index.ts b/src/index.ts index b3517fce8..a489278ab 100644 --- a/src/index.ts +++ b/src/index.ts @@ -478,7 +478,7 @@ export interface Props { export const type =

( props: P, name: string = getNameFromProps(props) -): InterfaceType, OutputOfProps

, mixed> => +): InterfaceType }, { [K in keyof P]: OutputOf }, mixed> => new InterfaceType( name, (m): m is TypeOfProps

=> { @@ -550,7 +550,7 @@ export type InputOfPartialProps

= { [K in keyof P]?: OutputO export const partial =

( props: P, name: string = `PartialType<${getNameFromProps(props)}>` -): PartialType, InputOfPartialProps

, mixed> => { +): PartialType }, { [K in keyof P]?: OutputOf }, mixed> => { const partials: Props = {} for (let k in props) { partials[k] = union([props[k], undefinedType]) @@ -602,7 +602,7 @@ export const dictionary = ( domain: D, codomain: C, name: string = `{ [K in ${domain.name}]: ${codomain.name} }` -): DictionaryType, OutputOfDictionary, mixed> => +): DictionaryType]: TypeOf }, { [K in OutputOf]: OutputOf }, mixed> => new DictionaryType( name, (m): m is TypeOfDictionary => @@ -955,7 +955,7 @@ export class StrictType

extends T export const strict =

( props: P, name: string = `StrictType<${getNameFromProps(props)}>` -): StrictType, OutputOfProps

, mixed> => { +): StrictType }, { [K in keyof P]: OutputOf }, mixed> => { const loose = type(props) return new StrictType( name, diff --git a/typings-checker/index.ts b/typings-checker/index.ts index d8eb081ea..427e6a734 100644 --- a/typings-checker/index.ts +++ b/typings-checker/index.ts @@ -104,7 +104,7 @@ const x11: I2T = { name: 'name', father: { surname: 'surname' } } const D1 = t.dictionary(t.keyof({ a: true }), t.number) // $ExpectError Type 'string' is not assignable to type 'number' const x12: TypeOf = { a: 's' } -// $ExpectError Type '{ c: number; }' is not assignable to type 'TypeOfDictionary, NumberType>' +// $ExpectError Type '{ c: number; }' is not assignable to type '{ a: number; }'. const x12_2: TypeOf = { c: 1 } const x13: TypeOf = { a: 1 } @@ -306,7 +306,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 'TypeOfProps<{ type: LiteralType<"a">; }> | TypeOfProps<{ type: LiteralType<"b">; }>' +// $ExpectError Type 'true' is not assignable to type '{ type: "a"; } | { type: "b"; }' const x36: TypeOf = true const x37: TypeOf = { type: 'a' } const x38: TypeOf = { type: 'b' }