How to use the tsd.expectNotAssignable function in tsd

To help you get started, we’ve selected a few tsd examples, based on popular ways it is used in public projects.

github fregante / webext-storage-cache / index.test-d.ts View on Github external
import {expectType, expectNotAssignable, expectAssignable} from 'tsd';
import cache from '.';

type Primitive = boolean | number | string;
type Value = Primitive | Primitive[] | Record<string, unknown>;


expectType<Promise<Value | undefined>>(cache.get('key'));
expectType<Promise<string | undefined>>(cache.get<string>('key'));
expectNotAssignable<Promise<number | undefined>>(cache.get<string>('key'));

expectAssignable<Promise<number>>(cache.set('key', 1));
expectAssignable<Promise<boolean>>(cache.set('key', true));
expectAssignable<Promise<[boolean, string]>>(cache.set('key', [true, 'string']));
expectAssignable<Promise<Record<string, any[]>>>(cache.set('key', {wow: [true, 'string']}));
expectAssignable<Promise<number>>(cache.set('key', 1, 1));


Check TypeScript type definitions

Latest version published 21 days ago

Package Health Score

86 / 100
Full package analysis