Skip to content

Commit 2a17508

Browse files
authored
Check for Optional Configuration in client constructor (#859)
1 parent 54be063 commit 2a17508

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/ServiceBareBonesClientGenerator.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,12 +333,14 @@ private void generateClientProperties() {
333333
}
334334

335335
private void generateConstructor() {
336-
writer.openBlock("constructor(configuration: $L) {", "}", configType, () -> {
336+
writer.addImport("CheckOptionalClientConfig", "__CheckOptionalClientConfig",
337+
TypeScriptDependency.SMITHY_TYPES);
338+
writer.openBlock("constructor(...[configuration]: __CheckOptionalClientConfig<$L>) {", "}", configType, () -> {
337339
// Hook for adding/changing the client constructor.
338340
writer.pushState(CLIENT_CONSTRUCTOR_SECTION);
339341

340342
int configVariable = 0;
341-
writer.write("let $L = __getRuntimeConfig(configuration);",
343+
writer.write("let $L = __getRuntimeConfig(configuration || {});",
342344
generateConfigVariable(configVariable));
343345

344346
if (service.hasTrait(EndpointRuleSetTrait.class)) {

0 commit comments

Comments
 (0)