Skip to content

Comments

chore(spec2cdk): handle undefined properties in the reference interfaces#37040

Open
leonmk-aws wants to merge 1 commit intomainfrom
leonk/optional-props
Open

chore(spec2cdk): handle undefined properties in the reference interfaces#37040
leonmk-aws wants to merge 1 commit intomainfrom
leonk/optional-props

Conversation

@leonmk-aws
Copy link
Contributor

@leonmk-aws leonmk-aws commented Feb 20, 2026

Issue # (if applicable)

Closes #.

Reason for this change

When a ref interface property is optional (e.g. workteamName?: string), the generated constructor code that extracts values from ref objects via optional chaining (?.ref?.property) would cause a compile time error.

Description of changes

  • Added getRefProperty utility that extracts a property from a ref object and throws a TypeError if the ref exists but the target property is undefined. Returns undefined when the ref itself is null, allowing ?? fallback chains to work naturally.

  • Added overloads to ensureStringOrUndefined so TypeScript correctly narrows the return type:

    • undefined input → returns undefined
    • {} input → returns string
    • {} | undefined input → returns string | undefined

Before

this.functionName = (props.functionName as IFunctionRef)?.functionRef?.functionName
  ?? cdk.ensureStringOrUndefined(props.functionName, "functionName", "lambda.IFunctionRef | string");

After

this.functionName = cdk.getRefProperty((props.functionName as IFunctionRef)?.functionRef, 'functionName')
  ?? cdk.ensureStringOrUndefined(props.functionName, "functionName", "lambda.IFunctionRef | string");

Description of how you validated changes

Added unit tests for the new function.

Checklist


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@leonmk-aws leonmk-aws requested a review from a team as a code owner February 20, 2026 15:06
@aws-cdk-automation aws-cdk-automation requested a review from a team February 20, 2026 15:06
@github-actions github-actions bot added the p2 label Feb 20, 2026
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Feb 20, 2026
@aws-cdk-automation aws-cdk-automation added the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Feb 20, 2026
@leonmk-aws leonmk-aws added the pr/request-cli-integ-tests Request CLI integ tests to be run. You will need to review the code and approve the deployment. label Feb 20, 2026
@leonmk-aws leonmk-aws deployed to test-pipeline February 20, 2026 15:57 — with GitHub Actions Active
@aws-cdk-automation
Copy link
Collaborator

➡️ PR build request submitted to test-main-pipeline ⬅️

A maintainer must now check the pipeline and add the pr-linter/cli-integ-tested label once the pipeline succeeds.

@leonmk-aws leonmk-aws removed the pr/request-cli-integ-tests Request CLI integ tests to be run. You will need to review the code and approve the deployment. label Feb 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contribution/core This is a PR that came from AWS. p2 pr/needs-maintainer-review This PR needs a review from a Core Team Member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants