type-fest/test-d/conditional-pick.ts
2022-08-29 15:23:09 +07:00

29 lines
753 B
TypeScript

import {expectType} from 'tsd';
import type {ConditionalPick, Primitive} from '../index';
class Awesome {
name!: string;
successes!: number;
failures!: bigint;
run(): void {
// Empty
}
}
type Example = {
a: string;
b?: string | number;
c?: string;
d: Record<string, unknown>;
};
declare const exampleConditionalPick: ConditionalPick<Example, string>;
expectType< {a: string}>(exampleConditionalPick);
declare const awesomeConditionalPick: ConditionalPick<Awesome, Primitive>;
expectType<{name: string; successes: number; failures: bigint}>(awesomeConditionalPick);
declare const exampleConditionalPickWithUndefined: ConditionalPick<Example, string | undefined>;
expectType<{a: string; c?: string}>(exampleConditionalPickWithUndefined);