Skip to content

Commit 3ac6747

Browse files
trivikrsrchase
authored andcommitted
Use Record type in place of Object (smithy-lang#557)
* Use Record type instead Object type * Update protocol-test-form-urlencoded-stub.ts * Change Object -> Record in doc
1 parent 42488ae commit 3ac6747

File tree

6 files changed

+12
-12
lines changed

6 files changed

+12
-12
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ private void writeConstraintValidatorType(TypeScriptWriter writer, Shape shape)
530530
Shape collectionMemberTargetShape = model.expectShape(collectionMemberShape.getTarget());
531531
writer.writeInline("Iterable<$T>", getSymbolForValidatedType(collectionMemberTargetShape));
532532
} else if (shape.isMapShape()) {
533-
writer.writeInline("{ [key: string]: $T }", getSymbolForValidatedType(((MapShape) shape).getValue()));
533+
writer.writeInline("Record<string, $T>", getSymbolForValidatedType(((MapShape) shape).getValue()));
534534
} else if (shape instanceof SimpleShape) {
535535
writer.writeInline("$T", getSymbolForValidatedType(shape));
536536
} else {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ public Symbol setShape(SetShape shape) {
175175
*
176176
* <pre>{@code
177177
* interface MyStructureShape {
178-
* memberPointingToMap: {[key: string]: string};
178+
* memberPointingToMap: Record<string, string>;
179179
* }
180180
* }</pre>
181181
*
@@ -184,7 +184,7 @@ public Symbol setShape(SetShape shape) {
184184
@Override
185185
public Symbol mapShape(MapShape shape) {
186186
Symbol reference = toSymbol(shape.getValue());
187-
return createSymbolBuilder(shape, format("{ [key: string]: %s }", reference.getName()), null)
187+
return createSymbolBuilder(shape, format("Record<string, %s>", reference.getName()), null)
188188
.addReference(reference)
189189
.build();
190190
}

smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/integration/DocumentShapeDeserVisitor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ protected Void getDefault(Shape shape) {
177177
* <li>{@code context: SerdeContext}: a TypeScript type containing context and tools for type serde.</li>
178178
* </ul>
179179
*
180-
* <p>The function signature specifies a {@code { [key: string]: Field }} return type.
180+
* <p>The function signature specifies a {@code Record<string, Field>} return type.
181181
*
182182
* <p>This function would generate the following:
183183
*
@@ -408,7 +408,7 @@ public final Void listShape(ListShape shape) {
408408
* const deserializeAws_restJson1_1FieldMap = (
409409
* output: any,
410410
* context: SerdeContext
411-
* ): { [key: string]: Field } => {
411+
* ): Record<string, Field> => {
412412
* let mapParams: any = {};
413413
* Object.keys(output).forEach(key => {
414414
* mapParams[key] = deserializeAws_restJson1_1Field(output[key], context);

smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/integration/DocumentShapeSerVisitor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ protected Void getDefault(Shape shape) {
175175
*
176176
* <p>The function signature for this body will have two parameters available in scope:
177177
* <ul>
178-
* <li>{@code input: { [key: string]: Field }}: the type generated for the MapShape shape parameter.</li>
178+
* <li>{@code input: Record<string, Field>}: the type generated for the MapShape shape parameter.</li>
179179
* <li>{@code context: SerdeContext}: a TypeScript type containing context and tools for type serde.</li>
180180
* </ul>
181181
*
@@ -403,7 +403,7 @@ public final Void listShape(ListShape shape) {
403403
*
404404
* <pre>{@code
405405
* const serializeAws_restJson1_1FieldMap = (
406-
* input: { [key: string]: Field },
406+
* input: Record<string, Field>,
407407
* context: SerdeContext
408408
* ): any => {
409409
* let mapParams: any = {};

smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/integration/HttpBindingProtocolGenerator.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1867,7 +1867,7 @@ private void readMappedQueryBindings(GenerationContext context, HttpBinding mapp
18671867
if (valueShape instanceof CollectionShape) {
18681868
valueType = "string[]";
18691869
}
1870-
writer.write("let parsedQuery: { [key: string]: $L } = {}", valueType);
1870+
writer.write("let parsedQuery: Record<string, $L> = {}", valueType);
18711871
writer.openBlock("for (const [key, value] of Object.entries(query)) {", "}", () -> {
18721872
writer.write("let queryValue: string;");
18731873
final String parsedValue;
@@ -2315,12 +2315,12 @@ private HttpBinding readPayload(
23152315
} else if (target instanceof StructureShape) {
23162316
// If payload is a Structure, then we need to parse the string into JavaScript object.
23172317
writer.addImport("expectObject", "__expectObject", "@aws-sdk/smithy-client");
2318-
writer.write("const data: { [key: string]: any } | undefined "
2318+
writer.write("const data: Record<string, any> | undefined "
23192319
+ "= __expectObject(await parseBody(output.body, context));");
23202320
} else if (target instanceof UnionShape) {
23212321
// If payload is a Union, then we need to parse the string into JavaScript object.
23222322
writer.addImport("expectUnion", "__expectUnion", "@aws-sdk/smithy-client");
2323-
writer.write("const data: { [key: string]: any } | undefined "
2323+
writer.write("const data: Record<string, any> | undefined "
23242324
+ "= __expectUnion(await parseBody(output.body, context));");
23252325
} else if (target instanceof StringShape || target instanceof DocumentShape) {
23262326
// If payload is String or Document, we need to collect body and convert binary to string.

smithy-typescript-codegen/src/main/resources/software/amazon/smithy/typescript/codegen/protocol-test-form-urlencoded-stub.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
* discrepancies between the components.
44
*/
55
const compareEquivalentFormUrlencodedBodies = (expectedBody: string, generatedBody: string): Object => {
6-
const fromEntries = (components: string[][]): { [key: string]: string } => {
7-
const parts: { [key: string]: string } = {};
6+
const fromEntries = (components: string[][]): Record<string, string> => {
7+
const parts: Record<string, string> = {};
88

99
components.forEach(component => {
1010
parts[component[0]] = component[1];

0 commit comments

Comments
 (0)