You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
TypeScript doesn't allow me to pass objects with undefined props to the environment prop of a Lambda function.
This code could work but currently doesn't:
newFunction(this,'function',{environment: {myOptionalBucketName: thisBucketMayNotExist?.bucketName// <-- could work but doesn't }}
I would like to pass such object and let CDK deal with it.
Expected Behavior
TypeScript will not mark this as an error, my stack can be synthesized and deployed.
Current Behavior
I see a type error:
Type 'string | undefined' is not assignable to type 'string'.
Type 'undefined' is not assignable to type 'string'.ts(2322)
function.d.ts(72, 14): The expected type comes from property 'environment' which is declared here on type 'FunctionProps'
The type [key: string] : string specified in function.ts:L82 could be replaced with a Partial<[key: string] : string> (or a Partial<Record<string, string>>).
If needed, the passed values that are undefined should be filtered out before synth/deployment.
The workaround I need to have today is either conditionally append the prop in another statement or use a somewhat ugly conditional assignment with
I'm opening this ticket to see if the maintainers see the current behavior as a bug or as a feature. I am able to implement the change/fix if approved.
CDK CLI Version
2.103.1
Node.js Version
18.12.1
OS
MacOS
Language
TypeScript
The text was updated successfully, but these errors were encountered:
piotrekwitkowski
changed the title
aws-lambda: Allow undefined values to be passed to the environment prop of a Lambda function
aws-lambda: Allow undefined values to be passed to the environment prop of a Function
Oct 27, 2023
khushail
added
investigating
This issue is being investigated and/or work is in progress to resolve the issue.
and removed
needs-triage
This issue or PR still needs to be triaged.
labels
Oct 27, 2023
Describe the bug
TypeScript doesn't allow me to pass objects with undefined props to the environment prop of a Lambda function.
This code could work but currently doesn't:
I would like to pass such object and let CDK deal with it.
Expected Behavior
TypeScript will not mark this as an error, my stack can be synthesized and deployed.
Current Behavior
I see a type error:
Reproduction Steps
Can be reproduced with this code:
Possible Solution
The type
[key: string] : string
specified in function.ts:L82 could be replaced with aPartial<[key: string] : string>
(or aPartial<Record<string, string>>
).If needed, the passed values that are undefined should be filtered out before synth/deployment.
The workaround I need to have today is either conditionally append the prop in another statement or use a somewhat ugly conditional assignment with
Additional Information/Context
I'm opening this ticket to see if the maintainers see the current behavior as a bug or as a feature. I am able to implement the change/fix if approved.
CDK CLI Version
2.103.1
Node.js Version
18.12.1
OS
MacOS
Language
TypeScript
The text was updated successfully, but these errors were encountered: