import type { Client } from "../client"; import type { HttpHandlerOptions } from "../http"; import type { MetadataBearer } from "../response"; import type { Exact } from "./exact"; import type { AssertiveClient, NoUndefined, UncheckedClient } from "./no-undefined"; type A = { a: string; b: number | string; c: boolean | number | string; required: string | undefined; optional?: string; nested: A; }; { // it should remove undefined union from required fields. type T = NoUndefined; const assert1: Exact = true as const; const assert2: Exact = true as const; const assert3: Exact = true as const; } { type MyInput = { a: string | undefined; b: number | undefined; c: string | number | undefined; optional?: string; }; type MyOutput = { a?: string; b?: number; c?: string | number; r?: MyOutput; } & MetadataBearer; type MyConfig = { version: number; }; interface MyClient extends Client { getObject(args: MyInput, options?: HttpHandlerOptions): Promise; getObject(args: MyInput, cb: (err: any, data?: MyOutput) => void): void; getObject(args: MyInput, options: HttpHandlerOptions, cb: (err: any, data?: MyOutput) => void): void; putObject(args: MyInput, options?: HttpHandlerOptions): Promise; putObject(args: MyInput, cb: (err: any, data?: MyOutput) => void): void; putObject(args: MyInput, options: HttpHandlerOptions, cb: (err: any, data?: MyOutput) => void): void; } { // AssertiveClient should enforce union of undefined on inputs // but preserve undefined outputs. const c = (null as unknown) as AssertiveClient; const input = { a: "", b: 0, c: 0, }; const get = c.getObject(input); const output = (null as unknown) as Awaited; const assert1: Exact = true as const; const assert2: Exact = true as const; const assert3: Exact = true as const; if (output.r) { const assert4: Exact = true as const; const assert5: Exact = true as const; const assert6: Exact = true as const; } } { // UncheckedClient both removes union-undefined from inputs // and the nullability of outputs. const c = (null as unknown) as UncheckedClient; const input = { a: "", b: 0, c: 0, }; const get = c.getObject(input); const output = (null as unknown) as Awaited; const assert1: Exact = true as const; const assert2: Exact = true as const; const assert3: Exact = true as const; const assert4: Exact = true as const; const assert5: Exact = true as const; const assert6: Exact = true as const; } }