TS compilation error when exactOptionalPropertyTypes set true #23885
Replies: 8 comments 3 replies
-
Can confirm that I'm facing the same issue here, please refer https://devblogs.microsoft.com/typescript/announcing-typescript-4-4/#exact-optional-property-types to know why this is an issue. |
Beta Was this translation helpful? Give feedback.
-
Hello, wondering if there is any updates on this issue. My current work around is to explicity cast the concrete class as the specific interface - vpc as IVpc or table as ITable. But for anyone using a later version of Typescript with a default config will be hitting this issue. |
Beta Was this translation helpful? Give feedback.
-
Same here 😮💨
Temp fix is using |
Beta Was this translation helpful? Give feedback.
-
This is a TypeScript 4.4 feature and the CDK is on 3.9. At this time we cannot upgrade our TypeScript version so there's no action item we can take here. See aws/aws-cdk-rfcs#373 for more information on this. Given the lack of actions to be taken at this time, I'm going to convert this to a discussion so that others can find this context. |
Beta Was this translation helpful? Give feedback.
-
Is there any update on this issue? Seems like the mentioned RFC has been accepted and merged. So what would be the next steps in order to update the types in CDK so they don’t conflict with enabled |
Beta Was this translation helpful? Give feedback.
-
What is holding the CDK team back from just adding |
Beta Was this translation helpful? Give feedback.
-
Hello, I apologize for the lack of update. I'll start a discussion thread with the internal CDK team and update this thread. IMO, I don't see anything blocking the addition of |
Beta Was this translation helpful? Give feedback.
-
Thanks for reporting this! The issue occurs because While this is something CDK could support, fixing it would require extensive changes across the entire codebase, adding Workaround for Defining a New ConstructIf you're defining a CDK construct and the property requires something like new SomeL2Construct(stack, 'id', {
...myProp && { prop: myProp }
}); This ensures that prop is only included when myProp is defined, preventing TypeScript errors caused by For Other ScenariosIf there’s no viable workaround for your specific case, feel free to submit a PR as a temporary fix. We also welcome contributions to help resolve these issues across CDK. If anyone is willing to submit a PR to add this flag and help us enable |
Beta Was this translation helpful? Give feedback.
-
General Issue
TypeScript compilation fails when exactOptionalPropertyTypes is set to true
The Question
Compilation fails when
exactOptionalPropertyTypes
is set to true.Several other modules also have the same error.
CDK CLI Version
2.13.0
Framework Version
2.13.0
Node.js Version
16.12.0
OS
macOS Big Sur
Language
Typescript
Language Version
TypeScript (4.5.5)
Other information
Most likely, replacing
readonly latestDeployment?: Deployment;
withreadonly latestDeployment: Deployment | undefined;
should fix the issue. I can try this as my first issue in the project. Please let me know if I should make a pull request.Beta Was this translation helpful? Give feedback.
All reactions