-
Notifications
You must be signed in to change notification settings - Fork 612
Support for exactOptionalPropertyTypes
#4017
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
Comments
Hi @laverdet - sorry for the long wait. We recently had a team discussion about this and my colleague left a comment with the explanation and workaround on the other similar issue: #5992
We would still be happy to further assist you if you have any specific issue around this. Thanks again for reaching out. |
@aBurmeseDev I fear that we have had a miscommunication. I will take blame for that because I did not provide enough information. The As a case study, the DefinitelyTyped project on GitHub (which represents the entire This series of commits touches over 500,000 lines of declarations and is nothing but this kind of thing: --- a/types/zarinpal-checkout/index.d.ts
+++ b/types/zarinpal-checkout/index.d.ts
@@ -14,8 +14,8 @@ declare namespace ZarinPal {
Amount: number;
CallbackURL: string;
Description: string;
- Email?: string;
- Mobile?: string;
+ Email?: string | undefined;
+ Mobile?: string | undefined;
}
interface PaymentRequestOutput { The issue is not that AWS should remove For a concrete example, as it relates to AWS, consider: import type { DynamoDBClient } from "@aws-sdk/client-dynamodb";
import { GetItemCommand } from "@aws-sdk/client-dynamodb";
declare const client: DynamoDBClient;
// Compiles fine.
await client.send(new GetItemCommand({
Key: {},
TableName: "",
}));
const ConsistentRead = undefined;
// Argument of type '{ Key: {}; TableName: string; ConsistentRead: undefined; }' is not assignable
// to parameter of type 'GetItemCommandInput' with 'exactOptionalPropertyTypes: true'. Consider
// adding 'undefined' to the types of the target's properties.
// Types of property 'ConsistentRead' are incompatible.
// Type 'undefined' is not assignable to type 'boolean'
await client.send(new GetItemCommand({
Key: {},
TableName: "",
ConsistentRead,
})); The second invocation fails since This is the {
"compilerOptions": {
"module": "esnext",
"moduleResolution": "nodenext",
"target": "esnext",
"strict": true,
// 🚨 This was added in TypeScript 4.4 https://devblogs.microsoft.com/typescript/announcing-typescript-4-4/#exact-optional-property-types
"exactOptionalPropertyTypes": true,
},
} |
@aBurmeseDev would you mind reopening this issue? If I don't hear back I'll open a new one because I understand the team gets a lot of notifications, but there has been a misunderstanding here. |
@laverdet - thanks for providing detailed information, I'll look more into it and discuss it with the team. |
@aBurmeseDev @Kume @RanVaknin please let me know if you need any more information on this. |
@laverdet - will do and feel free to check back in for further updates. |
Addition of |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread. |
Describe the feature
TypeScript 4.4 added support for a setting in tsconfig.json:
exactOptionalPropertyTypes
. See the announcement here:https://devblogs.microsoft.com/typescript/announcing-typescript-4-4/#exact-optional-property-types
With this flag enabled,
undefined
is no longer assignable to optional members unless they explicitly haveundefined
in their signature.The AWS SDK gracefully handles the case where a parameter is specified but
undefined
. Specifically, the overwhelming majority of the SDK transmits requests withJSON.stringify
which will omitundefined
values from the payload entirely. Therefore, the AWS SDK should addundefined
to most of the generated d.ts input types.Use Case
exactOptionalPropertyTypes
brings the types of a project closer to the actual shape during runtime. It should be used in all new projects when possible. Currently, using the AWS SDK with this option enabled is unreasonably cumbersome.Proposed Solution
I believe this can be implemented with minor changes to the code generation. Instead of outputting
?:
you will output?: undefined |
.Other Information
This is the PR of the feature from TypeScript microsoft/TypeScript#43947
Acknowledgements
SDK version used
v3.184.0
Environment details (OS name and version, etc.)
N/A
The text was updated successfully, but these errors were encountered: