diff --git a/.changeset/cold-ligers-punch.md b/.changeset/cold-ligers-punch.md new file mode 100644 index 00000000000..df9e69c61ca --- /dev/null +++ b/.changeset/cold-ligers-punch.md @@ -0,0 +1,5 @@ +--- +"@smithy/types": minor +--- + +fix type transforms for method signatures with no arguments diff --git a/packages/types/src/client.ts b/packages/types/src/client.ts index 576b2220c8d..cc1a4b651a1 100644 --- a/packages/types/src/client.ts +++ b/packages/types/src/client.ts @@ -53,6 +53,19 @@ export interface InvokeMethod void): Promise | void; } +/** + * @public + * + * Signature that appears on aggregated clients' methods when argument is optional. + */ +export interface InvokeMethodOptionalArgs { + (): Promise; + (input: InputType, options?: any): Promise; + (input: InputType, cb: (err: any, data?: OutputType) => void): void; + (input: InputType, options: any, cb: (err: any, data?: OutputType) => void): void; + (input: InputType, options?: any, cb?: (err: any, data?: OutputType) => void): Promise | void; +} + /** * A general interface for service clients, idempotent to browser or node clients * This type corresponds to SmithyClient(https://github.com/aws/aws-sdk-js-v3/blob/main/packages/smithy-client/src/client.ts). diff --git a/packages/types/src/transform/no-undefined.spec.ts b/packages/types/src/transform/no-undefined.spec.ts index 724d44beabc..85378e50952 100644 --- a/packages/types/src/transform/no-undefined.spec.ts +++ b/packages/types/src/transform/no-undefined.spec.ts @@ -49,6 +49,11 @@ type A = { 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; + + listObjects(): Promise; + listObjects(args: MyInput, options?: HttpHandlerOptions): Promise; + listObjects(args: MyInput, cb: (err: any, data?: MyOutput) => void): void; + listObjects(args: MyInput, options: HttpHandlerOptions, cb: (err: any, data?: MyOutput) => void): void; } { @@ -92,4 +97,20 @@ type A = { const assert5: Exact = true as const; const assert6: Exact = true as const; } + + { + // Handles methods with optionally zero args. + const c = (null as unknown) as AssertiveClient; + const list = c.listObjects(); + 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; + } + } } diff --git a/packages/types/src/transform/no-undefined.ts b/packages/types/src/transform/no-undefined.ts index eeb52cdd63a..f259bc1a83c 100644 --- a/packages/types/src/transform/no-undefined.ts +++ b/packages/types/src/transform/no-undefined.ts @@ -1,4 +1,4 @@ -import type { InvokeFunction, InvokeMethod } from "../client"; +import type { InvokeFunction, InvokeMethod, InvokeMethodOptionalArgs } from "../client"; /** * @public @@ -59,8 +59,10 @@ export type RecursiveRequired = T extends Function */ type NarrowClientIOTypes = { [key in keyof ClientType]: [ClientType[key]] extends [ - InvokeFunction + InvokeMethodOptionalArgs ] + ? InvokeMethodOptionalArgs, NoUndefined> + : [ClientType[key]] extends [InvokeFunction] ? InvokeFunction, NoUndefined, ConfigType> : [ClientType[key]] extends [InvokeMethod] ? InvokeMethod, NoUndefined> @@ -74,8 +76,10 @@ type NarrowClientIOTypes = { */ type UncheckedClientOutputTypes = { [key in keyof ClientType]: [ClientType[key]] extends [ - InvokeFunction + InvokeMethodOptionalArgs ] + ? InvokeMethodOptionalArgs, RecursiveRequired> + : [ClientType[key]] extends [InvokeFunction] ? InvokeFunction, RecursiveRequired, ConfigType> : [ClientType[key]] extends [InvokeMethod] ? InvokeMethod, RecursiveRequired>