Skip to content

Use Record type in place of Object #557

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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