import {expectType} from 'tsd'; import type {RequiredKeysOf, UnknownRecord} from '../index.d.ts'; type TestType1 = { a: string; b?: boolean; }; type TestType2 = { a?: string; b?: boolean; }; type TestType3 = { a: string; b: boolean; }; type RequiredKeysOf1 = RequiredKeysOf; type RequiredKeysOf2 = RequiredKeysOf; type RequiredKeysOf3 = RequiredKeysOf; declare const test1: RequiredKeysOf1; declare const test2: RequiredKeysOf2; declare const test3: RequiredKeysOf3; expectType<'a'>(test1); expectType(test2); expectType<'a' | 'b'>(test3); expectType<'a' | 'c'>({} as RequiredKeysOf<{readonly a: string; readonly b?: number; c: boolean; d?: string}>); // Unions expectType<'b' | 'c'>({} as RequiredKeysOf<{a?: string; b: number} | {readonly c: string; readonly d?: number}>); expectType<'a' | 'b'>({} as RequiredKeysOf<{a?: string; b?: number} | {a: string; b: number}>); // Arrays expectType({} as RequiredKeysOf<[]>); expectType({} as RequiredKeysOf); expectType>({} as RequiredKeysOf<[string, number?, boolean?]>); expectType>({} as RequiredKeysOf<[string?] | readonly [string, number?] | [string, number, boolean?]>); // `RequiredKeysOf` should be assignable to `keyof T` type Assignability1 = unknown; type Test1 = Assignability1>; // `keyof T` should NOT be assignable to `RequiredKeysOf` type Assignability2> = unknown; // @ts-expect-error type Test2 = Assignability2; // `RequiredKeysOf` should be assignable to `PropertyKey` type Assignability3<_T, _K extends PropertyKey> = unknown; type Test3 = Assignability3>; // `PropertyKey` should NOT be assignable to `RequiredKeysOf` type Assignability4> = unknown; // @ts-expect-error type Test4 = Assignability4; // `RequiredKeysOf` should be assignable to `keyof T` even when `T` is constrained to `Record` type Assignability5, _K extends keyof T> = unknown; type Test5> = Assignability5>; // `RequiredKeysOf` should be assignable to `keyof T` even when `T` is constrained to `object` type Assignability6 = unknown; type Test6 = Assignability6>; // `RequiredKeysOf` should be assignable to `keyof T` even when `T` is constrained to `UnknownRecord` type Assignability7 = unknown; type Test7 = Assignability7>; // `keyof T` should NOT be assignable to `RequiredKeysOf` even when `T` is constrained to `Record` type Assignability8, _K extends RequiredKeysOf> = unknown; // @ts-expect-error type Test8> = Assignability8; // `keyof T` should NOT be assignable to `RequiredKeysOf` even when `T` is constrained to `object` type Assignability9> = unknown; // @ts-expect-error type Test9 = Assignability9; // `keyof T` should NOT be assignable to `RequiredKeysOf` even when `T` is constrained to `UnknownRecord` type Assignability10> = unknown; // @ts-expect-error type Test10 = Assignability10;