From 45b97086a5cec6991c88375411740273dc5328a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Linus=20Unneb=C3=A4ck?= Date: Fri, 10 Aug 2018 12:20:53 +0100 Subject: [PATCH] Fix assertions of union types --- test/typings.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/test/typings.ts b/test/typings.ts index 2f96408..6244d66 100644 --- a/test/typings.ts +++ b/test/typings.ts @@ -49,9 +49,8 @@ const personValidator = createValidator({ if (personValidator(input)) { assertType(input.name) - assertType(input.age) - input.age === undefined - input.age === 1 + if (typeof input.age !== 'undefined') assertType(input.age) + if (typeof input.age !== 'number') assertType(input.age) } const namesValidator = createValidator({ @@ -139,7 +138,8 @@ const user2Validator = createValidator({ if (user2Validator(input)) { assertType<{ first: string | undefined, last: string }>(input.name) - assertType(input.name.first) + if (typeof input.name.first !== 'undefined') assertType(input.name.first) + if (typeof input.name.first !== 'string') assertType(input.name.first) assertType(input.name.last) if (input.items !== undefined) { @@ -165,7 +165,9 @@ const specificValuesValidator = createValidator({ }) if (specificValuesValidator(input)) { - assertType(input) + if (input !== true && input !== 1000) assertType<'XX'>(input) + if (input !== 1000 && input !== 'XX') assertType(input) + if (input !== 'XX' && input !== true) assertType<1000>(input) } const metricValidator = createValidator({