Skip to content

Commit

Permalink
Use Record type in place of Object (#557)
Browse files Browse the repository at this point in the history
* Use Record type instead Object type

* Update protocol-test-form-urlencoded-stub.ts

* Change Object -> Record in doc
  • Loading branch information
trivikr authored Jun 3, 2022
1 parent b3f37fa commit a5e1755
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ private void writeConstraintValidatorType(TypeScriptWriter writer, Shape shape)
Shape collectionMemberTargetShape = model.expectShape(collectionMemberShape.getTarget());
writer.writeInline("Iterable<$T>", getSymbolForValidatedType(collectionMemberTargetShape));
} else if (shape.isMapShape()) {
writer.writeInline("{ [key: string]: $T }", getSymbolForValidatedType(((MapShape) shape).getValue()));
writer.writeInline("Record<string, $T>", getSymbolForValidatedType(((MapShape) shape).getValue()));
} else if (shape instanceof SimpleShape) {
writer.writeInline("$T", getSymbolForValidatedType(shape));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public Symbol setShape(SetShape shape) {
*
* <pre>{@code
* interface MyStructureShape {
* memberPointingToMap: {[key: string]: string};
* memberPointingToMap: Record<string, string>;
* }
* }</pre>
*
Expand All @@ -184,7 +184,7 @@ public Symbol setShape(SetShape shape) {
@Override
public Symbol mapShape(MapShape shape) {
Symbol reference = toSymbol(shape.getValue());
return createSymbolBuilder(shape, format("{ [key: string]: %s }", reference.getName()), null)
return createSymbolBuilder(shape, format("Record<string, %s>", reference.getName()), null)
.addReference(reference)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ protected Void getDefault(Shape shape) {
* <li>{@code context: SerdeContext}: a TypeScript type containing context and tools for type serde.</li>
* </ul>
*
* <p>The function signature specifies a {@code { [key: string]: Field }} return type.
* <p>The function signature specifies a {@code Record<string, Field>} return type.
*
* <p>This function would generate the following:
*
Expand Down Expand Up @@ -408,7 +408,7 @@ public final Void listShape(ListShape shape) {
* const deserializeAws_restJson1_1FieldMap = (
* output: any,
* context: SerdeContext
* ): { [key: string]: Field } => {
* ): Record<string, Field> => {
* let mapParams: any = {};
* Object.keys(output).forEach(key => {
* mapParams[key] = deserializeAws_restJson1_1Field(output[key], context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ protected Void getDefault(Shape shape) {
*
* <p>The function signature for this body will have two parameters available in scope:
* <ul>
* <li>{@code input: { [key: string]: Field }}: the type generated for the MapShape shape parameter.</li>
* <li>{@code input: Record<string, Field>}: the type generated for the MapShape shape parameter.</li>
* <li>{@code context: SerdeContext}: a TypeScript type containing context and tools for type serde.</li>
* </ul>
*
Expand Down Expand Up @@ -403,7 +403,7 @@ public final Void listShape(ListShape shape) {
*
* <pre>{@code
* const serializeAws_restJson1_1FieldMap = (
* input: { [key: string]: Field },
* input: Record<string, Field>,
* context: SerdeContext
* ): any => {
* let mapParams: any = {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1867,7 +1867,7 @@ private void readMappedQueryBindings(GenerationContext context, HttpBinding mapp
if (valueShape instanceof CollectionShape) {
valueType = "string[]";
}
writer.write("let parsedQuery: { [key: string]: $L } = {}", valueType);
writer.write("let parsedQuery: Record<string, $L> = {}", valueType);
writer.openBlock("for (const [key, value] of Object.entries(query)) {", "}", () -> {
writer.write("let queryValue: string;");
final String parsedValue;
Expand Down Expand Up @@ -2315,12 +2315,12 @@ private HttpBinding readPayload(
} else if (target instanceof StructureShape) {
// If payload is a Structure, then we need to parse the string into JavaScript object.
writer.addImport("expectObject", "__expectObject", "@aws-sdk/smithy-client");
writer.write("const data: { [key: string]: any } | undefined "
writer.write("const data: Record<string, any> | undefined "
+ "= __expectObject(await parseBody(output.body, context));");
} else if (target instanceof UnionShape) {
// If payload is a Union, then we need to parse the string into JavaScript object.
writer.addImport("expectUnion", "__expectUnion", "@aws-sdk/smithy-client");
writer.write("const data: { [key: string]: any } | undefined "
writer.write("const data: Record<string, any> | undefined "
+ "= __expectUnion(await parseBody(output.body, context));");
} else if (target instanceof StringShape || target instanceof DocumentShape) {
// If payload is String or Document, we need to collect body and convert binary to string.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
* discrepancies between the components.
*/
const compareEquivalentFormUrlencodedBodies = (expectedBody: string, generatedBody: string): Object => {
const fromEntries = (components: string[][]): { [key: string]: string } => {
const parts: { [key: string]: string } = {};
const fromEntries = (components: string[][]): Record<string, string> => {
const parts: Record<string, string> = {};

components.forEach(component => {
parts[component[0]] = component[1];
Expand Down

0 comments on commit a5e1755

Please sign in to comment.