mirror of
https://github.com/sindresorhus/type-fest.git
synced 2026-02-01 15:59:43 +00:00
36 lines
1002 B
TypeScript
36 lines
1002 B
TypeScript
import {expectAssignable, expectNotType, expectType} from 'tsd';
|
|
import type {TupleToUnion} from '../index';
|
|
|
|
const options = ['a', 'b', 'c'] as const;
|
|
type Options = TupleToUnion<typeof options>;
|
|
|
|
const a: Options = 'a';
|
|
expectAssignable<Options>(a);
|
|
expectType<'a'>(a);
|
|
expectNotType<'b'>(a);
|
|
expectNotType<'c'>(a);
|
|
|
|
const b: Options = 'b';
|
|
expectAssignable<Options>(b);
|
|
expectNotType<'a'>(b);
|
|
expectType<'b'>(b);
|
|
expectNotType<'c'>(b);
|
|
|
|
const c: Options = 'c';
|
|
expectAssignable<Options>(c);
|
|
expectNotType<'a'>(c);
|
|
expectNotType<'b'>(c);
|
|
expectType<'c'>(c);
|
|
|
|
declare const notAnArray: TupleToUnion<[]>;
|
|
expectType<never>(notAnArray);
|
|
|
|
declare const worksWithArrays: TupleToUnion<Array<string | number>>;
|
|
expectType<string | number>(worksWithArrays);
|
|
|
|
declare const resolvesToNeverForNonArrays: TupleToUnion<string | number>;
|
|
expectType<never>(resolvesToNeverForNonArrays);
|
|
|
|
declare const infiniteRestArguments: TupleToUnion<[string, ...number[]]>;
|
|
expectType<string | number>(infiniteRestArguments);
|