import {expectAssignable, expectType} from 'tsd'; import type {RequireAtLeastOne, Simplify} from '../index.d.ts'; type SystemMessages = { default: string; macos?: string; linux?: string; windows?: string; optional?: string; }; type ValidMessages = RequireAtLeastOne; declare const test: (_: ValidMessages) => void; test({macos: 'hey', default: 'hello'}); test({linux: 'sup', default: 'hello', optional: 'howdy'}); test({macos: 'hey', linux: 'sup', windows: 'hi', default: 'hello'}); // @ts-expect-error test({}); // @ts-expect-error test({macos: 'hey'}); // @ts-expect-error test({default: 'hello'}); declare const testWithoutKeys: (_: RequireAtLeastOne<{a: number; b: number}>) => void; testWithoutKeys({a: 1}); testWithoutKeys({b: 2}); testWithoutKeys({a: 1, b: 2}); // @ts-expect-error testWithoutKeys({}); type MessageBoard = (messages: M) => string; expectAssignable>( ({macos = '', linux = '🐧', windows = '⊞'}) => `${linux} + ${windows} = ${macos}`, ); expectType<{a: number; b?: string} | {a?: number; b: string}>( {} as Simplify>, // `Simplify` is required for the assertion to pass ); expectType<{a: number; b?: string} | {a?: number; b: string}>( {} as Simplify>, // `Simplify` is required for the assertion to pass ); expectType<{a: number; b?: string; c?: boolean} | {a?: number; b: string; c?: boolean} | {a?: number; b?: string; c: boolean}>( {} as Simplify>, // `Simplify` is required for the assertion to pass ); expectType<{a: number; b?: string; c?: boolean} | {a?: number; b: string; c?: boolean} | {a?: number; b?: string; c: boolean}>( {} as Simplify>, // `Simplify` is required for the assertion to pass ); expectType({} as RequireAtLeastOne<{}>); expectType({} as RequireAtLeastOne<{a: string; b: number}, never>); expectType({} as RequireAtLeastOne); expectType({} as RequireAtLeastOne); expectType({} as RequireAtLeastOne); expectType({} as RequireAtLeastOne); expectType({} as RequireAtLeastOne); expectType({} as RequireAtLeastOne); expectType({} as RequireAtLeastOne); expectType({} as RequireAtLeastOne);