Skip to content

Commit 67f5c72

Browse files
committed
test: add more cases
1 parent e9d6590 commit 67f5c72

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

test-d/extract-strict.ts

+40
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,43 @@ declare const invalidMixedFields: ExtractStrict<Foobar, {kind: 'foo'; d: string}
5959

6060
// @ts-expect-error
6161
declare const undefinedField: ExtractStrict<Foobar, undefined>;
62+
63+
// Primitives
64+
expectType<number>({} as ExtractStrict<string | number, number>);
65+
expectType<number | bigint>({} as ExtractStrict<string | number | bigint, number | bigint>);
66+
expectType<'bar' | 'baz'>({} as ExtractStrict<'foo' | 'bar' | 'baz', `b${string}`>);
67+
68+
// @ts-expect-error
69+
type invalid1 = ExtractStrict<string | number | boolean, number | bigint>;
70+
// @ts-expect-error
71+
type invalid2 = ExtractStrict<string, Uppercase<string>>;
72+
73+
// Optional and readonly modifiers
74+
expectType<{a: string; b: number}>({} as ExtractStrict<{a: string; b: number}, {a?: string}>);
75+
expectType<string[]>({} as ExtractStrict<string[], readonly string[]>);
76+
77+
// @ts-expect-error
78+
type invalid3 = ExtractStrict<{a?: string; b: number}, {a: string}>;
79+
// @ts-expect-error
80+
type invalid4 = ExtractStrict<readonly string[], string[]>;
81+
82+
// Index signatures
83+
expectType<{c: true; d: false}>(
84+
{} as ExtractStrict<{a: string; b: number} | {c: true; d: false}, Record<string, boolean>>,
85+
);
86+
87+
// @ts-expect-error
88+
type invalid5 = ExtractStrict<{a: string; b: number} | {c: true; d: false}, Record<string, string>>;
89+
90+
// `any` and `never`
91+
expectType<string | {a: string; b: number} | string[]>(
92+
{} as ExtractStrict<string | {a: string; b: number} | string[], any>,
93+
);
94+
expectType<never>(
95+
{} as ExtractStrict<string | {a: string; b: number} | string[], never>,
96+
);
97+
98+
// Miscellaneous
99+
expectType<[number, number]>({} as ExtractStrict<[number, number] | {x: number; y: number}, unknown[]>);
100+
expectType<[number, number]>({} as ExtractStrict<[number, number] | [number, number, number], {length: 2}>);
101+
expectType<{data: string | string[]}>({} as ExtractStrict<string | string[] | {data: string | string[]}, {data: unknown}>);

0 commit comments

Comments
 (0)