1.1.0 • Published 2 years ago

@yamatomo/expect-type v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

expect-type

Extracts the type defined in the code as a string for assertion.

usage

yarn add -D @yamatomo/expect-type
import { expectType } from '@yamatomo/expect-type';

type Test1 = string;
test('Test1 is string type', () => {
  expectType('Test1').toBe('string');
});

type Test2 = (string | number)[];
test('Test2 is (string | number)[]', () => {
  expectType('Test2').toBe('(string | number)[]');
});

test runner

Support vitest and jest

If you want to use it in a jest, the path to import should be as follows.

import { expectType } from '@yamatomo/expect-type/dist/jest';

It can also be run on other runners by using the type function.

import { type } from '@yamatomo/expect-type';

type Test = string;
expect(type('Test')).toEqual('string');

Samples are in the examples folder.