add expectTypeOf
This commit is contained in:
parent
b12fcef980
commit
05a131dffd
2 changed files with 12 additions and 12 deletions
|
|
@ -61,7 +61,9 @@
|
||||||
"ts-node": "^10.9.1",
|
"ts-node": "^10.9.1",
|
||||||
"typescript": "^5.0.4",
|
"typescript": "^5.0.4",
|
||||||
"xo": "^0.54.2",
|
"xo": "^0.54.2",
|
||||||
"zen-observable": "^0.10.0"
|
"zen-observable": "^0.10.0",
|
||||||
|
"expect-type": "^0.16.0"
|
||||||
|
|
||||||
},
|
},
|
||||||
"sideEffects": false,
|
"sideEffects": false,
|
||||||
"ava": {
|
"ava": {
|
||||||
|
|
|
||||||
20
test/test.ts
20
test/test.ts
|
|
@ -8,6 +8,7 @@ import test, {type ExecutionContext} from 'ava';
|
||||||
import {JSDOM} from 'jsdom';
|
import {JSDOM} from 'jsdom';
|
||||||
import {Subject, Observable} from 'rxjs';
|
import {Subject, Observable} from 'rxjs';
|
||||||
import {temporaryFile} from 'tempy';
|
import {temporaryFile} from 'tempy';
|
||||||
|
import {expectTypeOf} from 'expect-type';
|
||||||
import ZenObservable from 'zen-observable';
|
import ZenObservable from 'zen-observable';
|
||||||
import is, {
|
import is, {
|
||||||
assert,
|
assert,
|
||||||
|
|
@ -1483,30 +1484,26 @@ test('is.tupleLike', t => {
|
||||||
|
|
||||||
{
|
{
|
||||||
const tuple = [[false, 'unicorn'], 'string', true];
|
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, [is.array, is.string, is.boolean])) {
|
||||||
if (is.tupleLike(tuple[0], [is.boolean, is.string])) { // eslint-disable-line unicorn/no-lonely-if
|
if (is.tupleLike(tuple[0], [is.boolean, is.string])) { // eslint-disable-line unicorn/no-lonely-if
|
||||||
const value = tuple[0][1];
|
const value = tuple[0][1];
|
||||||
function_(value);
|
expectTypeOf(value).toEqualTypeOf<string>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
const tuple = [{isTest: true}, '1', true, null];
|
const tuple = [{isTest: true}, '1', true, null];
|
||||||
const function_ = (value: Record<string, unknown>) => value;
|
|
||||||
|
|
||||||
if (is.tupleLike(tuple, [is.nonEmptyObject, is.string, is.boolean, is.null_])) {
|
if (is.tupleLike(tuple, [is.nonEmptyObject, is.string, is.boolean, is.null_])) {
|
||||||
const value = tuple[0];
|
const value = tuple[0];
|
||||||
function_(value);
|
expectTypeOf(value).toEqualTypeOf<Record<string | number | symbol, unknown>>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
const tuple = [1, '1', true, null, undefined];
|
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_])) {
|
if (is.tupleLike(tuple, [is.number, is.string, is.boolean, is.undefined, is.null_])) {
|
||||||
const numericValue = tuple[0];
|
const numericValue = tuple[0];
|
||||||
|
|
@ -1514,11 +1511,12 @@ test('is.tupleLike', t => {
|
||||||
const booleanValue = tuple[2];
|
const booleanValue = tuple[2];
|
||||||
const undefinedValue = tuple[3];
|
const undefinedValue = tuple[3];
|
||||||
const nullValue = tuple[4];
|
const nullValue = tuple[4];
|
||||||
function_(numericValue);
|
expectTypeOf(numericValue).toEqualTypeOf<number>();
|
||||||
function_(stringValue);
|
expectTypeOf(stringValue).toEqualTypeOf<string>();
|
||||||
function_(booleanValue);
|
expectTypeOf(booleanValue).toEqualTypeOf<boolean>();
|
||||||
function_(undefinedValue);
|
expectTypeOf(undefinedValue).toEqualTypeOf<undefined>();
|
||||||
function_(nullValue);
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||||
|
expectTypeOf(nullValue).toEqualTypeOf<null>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue