import {expectType} from 'tsd'; import type {IsOptionalKeyOf} from '../source/is-optional-key-of.d.ts'; declare const never: never; declare const boolean: boolean; declare const symbol: unique symbol; // Base object type A = { a: string; b?: number; c: boolean; }; expectType>(false); expectType>(true); expectType>(false); // @ts-expect-error `d` is not in `keyof T` expectType>(false); // Index signature with optional keys type B = { [k: string]: string; }; expectType>(false); expectType>(true); // Optional + readonly type C = { readonly a?: number; b: string; }; expectType>(true); expectType>(false); // Required + readonly type D = { readonly x: boolean; y?: string; }; expectType>(false); expectType>(true); // Union type E1 = {a?: number}; type E2 = {a: number}; type E = E1 | E2; expectType>(boolean); // Intersection type F1 = {a?: number}; type F2 = {a: number}; type F = F1 & F2; expectType>(false); // Class class G { x?: string; y = 5; } expectType>(true); expectType>(false); type H = { [symbol]?: number; a: string; }; expectType>(true); expectType>(false); // Method and optional prop type I = { name: string; run?(): void; }; expectType>(true); expectType>(false); // Fully optional object type J = Partial<{ a: number; b: string; }>; expectType>(true); expectType>(true); // Non-optional but union with undefined type L = { a: string | undefined; b?: number; }; expectType>(false); expectType>(true); // Union of keys expectType>(boolean); expectType>(boolean); // @ts-expect-error expectType>(false); expectType>(false); type FullKeyUnion = keyof A; // 'a' | 'b' | 'c' expectType>(boolean); // @ts-expect-error expectType>(boolean); // 'x' is not in A, so filtered as false // `never` / `any type K = {a?: string}; expectType>(never); expectType>(never); expectType>(never); expectType>(never); expectType>(never); expectType>(never);