From 05a131dffd36ad65035ffa20c9b3afcde04c1520 Mon Sep 17 00:00:00 2001 From: Tal Mac Date: Sun, 23 Jul 2023 00:41:32 +0300 Subject: [PATCH] add expectTypeOf --- package.json | 4 +++- test/test.ts | 20 +++++++++----------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index 8e13525..9ae890b 100644 --- a/package.json +++ b/package.json @@ -61,7 +61,9 @@ "ts-node": "^10.9.1", "typescript": "^5.0.4", "xo": "^0.54.2", - "zen-observable": "^0.10.0" + "zen-observable": "^0.10.0", + "expect-type": "^0.16.0" + }, "sideEffects": false, "ava": { diff --git a/test/test.ts b/test/test.ts index 5db468e..7bd1aed 100644 --- a/test/test.ts +++ b/test/test.ts @@ -8,6 +8,7 @@ import test, {type ExecutionContext} from 'ava'; import {JSDOM} from 'jsdom'; import {Subject, Observable} from 'rxjs'; import {temporaryFile} from 'tempy'; +import {expectTypeOf} from 'expect-type'; import ZenObservable from 'zen-observable'; import is, { assert, @@ -1483,30 +1484,26 @@ test('is.tupleLike', t => { { const tuple = [[false, 'unicorn'], 'string', true]; - const function_ = (value: string) => value; if (is.tupleLike(tuple, [is.array, is.string, is.boolean])) { if (is.tupleLike(tuple[0], [is.boolean, is.string])) { // eslint-disable-line unicorn/no-lonely-if const value = tuple[0][1]; - function_(value); + expectTypeOf(value).toEqualTypeOf(); } } } { const tuple = [{isTest: true}, '1', true, null]; - const function_ = (value: Record) => value; if (is.tupleLike(tuple, [is.nonEmptyObject, is.string, is.boolean, is.null_])) { const value = tuple[0]; - function_(value); + expectTypeOf(value).toEqualTypeOf>(); } } { const tuple = [1, '1', true, null, undefined]; - // eslint-disable-next-line @typescript-eslint/ban-types - const function_ = (value: number | string | boolean | undefined | null) => value; if (is.tupleLike(tuple, [is.number, is.string, is.boolean, is.undefined, is.null_])) { const numericValue = tuple[0]; @@ -1514,11 +1511,12 @@ test('is.tupleLike', t => { const booleanValue = tuple[2]; const undefinedValue = tuple[3]; const nullValue = tuple[4]; - function_(numericValue); - function_(stringValue); - function_(booleanValue); - function_(undefinedValue); - function_(nullValue); + expectTypeOf(numericValue).toEqualTypeOf(); + expectTypeOf(stringValue).toEqualTypeOf(); + expectTypeOf(booleanValue).toEqualTypeOf(); + expectTypeOf(undefinedValue).toEqualTypeOf(); + // eslint-disable-next-line @typescript-eslint/ban-types + expectTypeOf(nullValue).toEqualTypeOf(); } } });