diff --git a/.changeset/curvy-pumas-return.md b/.changeset/curvy-pumas-return.md new file mode 100644 index 00000000000..bd65a5391dd --- /dev/null +++ b/.changeset/curvy-pumas-return.md @@ -0,0 +1,5 @@ +--- +"@smithy/types": minor +--- + +Add type to check optional Client Configuration diff --git a/packages/types/src/client.ts b/packages/types/src/client.ts index 81cdaec5ddf..e8d7fcbad01 100644 --- a/packages/types/src/client.ts +++ b/packages/types/src/client.ts @@ -1,6 +1,15 @@ import { Command } from "./command"; import { MiddlewareStack } from "./middleware"; import { MetadataBearer } from "./response"; +import { Exact } from "./util"; + +/** + * @public + * + * A type which checks if the client configuration is optional. + * If all entries of the client configuration are optional, it allows client creation without passing any config. + */ +export type CheckOptionalClientConfig = Exact, T> extends true ? [] | [T] : [T]; /** * @public diff --git a/packages/types/src/util.ts b/packages/types/src/util.ts index e5905ba2dbb..6b4433ef6be 100644 --- a/packages/types/src/util.ts +++ b/packages/types/src/util.ts @@ -2,6 +2,13 @@ import { Endpoint } from "./http"; import { FinalizeHandler, FinalizeHandlerArguments, FinalizeHandlerOutput } from "./middleware"; import { MetadataBearer } from "./response"; +/** + * @public + * + * A generic which checks if Type1 is exactly same as Type2. + */ +export type Exact = [Type1] extends [Type2] ? ([Type2] extends [Type1] ? true : false) : false; + /** * @public *