Skip to content

Typescript types for required and optional attributes are not generated correctly #5992

Closed
@rehos

Description

@rehos

Checkboxes for prior research

Describe the bug

Typescript types are for required and optional attributes are not generated corrrectly. I.e. required attributes can accept undefined. And optional attributes cannot accept undefined when setting the typescript compilation option exactOptionalPropertyTypes to true.

Fixing this will probably also fix this issue

SDK version number

3.540.0

Which JavaScript Runtime is this issue in?

Node.js

Details of the browser/Node.js/ReactNative version

v20.11.0

Reproduction Steps

Just look at the generated typescript types for all clients

Observed Behavior

Typescript types of required attributes are all generated as a union with their type and undefined. And optional attributes are not generated as a union with undefined which gives problems when setting the typescript compilation option exactOptionalPropertyTypes to true.

See for example the in the DynamoDB client the TableName and IndexName attributes in the type QueryInput:

export interface QueryInput {
  TableName: string | undefined;
  IndexName?: string;

 // omitted other attributes

Expected Behavior

I expect required attributes cannot be set to undefined while optional attributes can accept undefined. Also when setting the typescript compilation option exactOptionalPropertyTypes to true.

So I expected that the generated code for the example above is generated as:

export interface QueryInput {
  TableName: string;
  IndexName?: string | undefined;

  // omitted other attributes

Possible Solution

Probably the following line in DocumentClientCommandGenerator.java:

String typeSuffix = isRequiredMember(member) ? " | undefined" : "";

should be changed to:

String typeSuffix = isRequiredMember(member) ? "" : " | undefined";

Additional Information/Context

No response

Metadata

Metadata

Assignees

Labels

closed-for-stalenessfeature-requestNew feature or enhancement. May require GitHub community feedback.p2This is a standard priority issue

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions