|
| 1 | +# TypeScript |
| 2 | + |
| 3 | +The AWS SDK for JavaScript v3 is written in TypeScript. This allows easier generation of [API documentation](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/), and provides type hints and autocompletion to code editors, whether you are |
| 4 | +using JavaScript or TypeScript. |
| 5 | + |
| 6 | +### Minimum supported TypeScript version |
| 7 | + |
| 8 | +The SDK does not have an official minimum supported TypeScript version. We recommend using a recent version of TypeScript. |
| 9 | +The current version of TypeScript used in development of the AWS SDK can be seen in the root `package.json` file. |
| 10 | + |
| 11 | +## Common TypeScript-related questions in the AWS SDK for JavaScript (v3) |
| 12 | + |
| 13 | +#### Why are operation request and response structures unions with `| undefined`? |
| 14 | + |
| 15 | +This allows more flexibility when it comes to AWS service APIs changing over time without needing to update your SDK client version, and encourages defensive checking of API responses. |
| 16 | +If you acknowledge the risks of not runtime-checking response object structures and would like to skip that, there is a `@smithy/types` type transform that can be applied to AWS SDK clients. |
| 17 | + |
| 18 | +For usage, see https://github.com/smithy-lang/smithy-typescript/tree/main/packages/types#scenario-removing--undefined-from-input-and-output-structures. |
| 19 | + |
| 20 | +#### Why are streaming output values a union type? |
| 21 | + |
| 22 | +The AWS SDK clients accept an optional runtime-provided value for `requestHandler` (see [requestHandler](https://github.com/aws/aws-sdk-js-v3/blob/main/supplemental-docs/CLIENTS.md#request-handler-requesthandler)). |
| 23 | +Because the implementation of the requestHandler varies both by platform (`node:https`-based for Node.js and `fetch`-based for browsers) and by service, and |
| 24 | +due to constraints from historical design decisions, the streaming response implementation is not precisely known at compile time. |
| 25 | + |
| 26 | +The type union describes why each member of the union exists ([source code](https://github.com/aws/aws-sdk-js-v3/blob/main/supplemental-docs/CLIENTS.md#request-handler-requesthandler) comments). |
| 27 | + |
| 28 | +If you would like to narrow the type of streaming responses, for example for AWS S3 getObject, there is another type transform that can be applied to clients, with instructions at |
| 29 | +`@smithy/types` https://github.com/smithy-lang/smithy-typescript/tree/main/packages/types#scenario-narrowing-a-smithy-typescript-generated-clients-output-payload-blob-types. |
0 commit comments