Skip to content

feat(aws-cdk-lib): all L1s now have a isCfn<ResourceName> static helper to check if a value is this L1 resource#36243

Merged
mergify[bot] merged 2 commits intomainfrom
mrgrain/feat/isCfnX-method
Dec 1, 2025
Merged

feat(aws-cdk-lib): all L1s now have a isCfn<ResourceName> static helper to check if a value is this L1 resource#36243
mergify[bot] merged 2 commits intomainfrom
mrgrain/feat/isCfnX-method

Conversation

@mrgrain
Copy link
Copy Markdown
Contributor

@mrgrain mrgrain commented Nov 29, 2025

Issue # (if applicable)

N/A

Reason for this change

CloudFormation resource classes (CfnX) lack a type-safe way to check if an object is an instance of a specific resource type. This makes it difficult to perform runtime type checking with proper TypeScript type narrowing.

Description of changes

Adds a static isCfn<Resource> method to all generated CloudFormation resource classes. This method:

  • Checks if the object is a CfnResource using the base class method
  • Verifies the cfnResourceType matches the specific resource type
  • Returns a TypeScript type predicate for proper type narrowing

Example generated method:

public static isCfnBucket(x: any): x is CfnBucket {
  return CfnResource.isCfnResource(x) && x.cfnResourceType === CfnBucket.CFN_RESOURCE_TYPE_NAME;
}

Implementation adds the makeIsAResource() method to the ResourceClass in spec2cdk, which generates this method for all CloudFormation resources.

Describe any new or updated permissions being added

None

Description of how you validated changes

Updated snapshot tests verify the method is generated correctly for all resource types.

Checklist


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

…lper to check if something is this L1 resource
@github-actions github-actions bot added the p2 label Nov 29, 2025
@aws-cdk-automation aws-cdk-automation requested a review from a team November 29, 2025 13:43
@mrgrain mrgrain changed the title feat(spec2cdk): add isCfnX type guard methods to CloudFormation resources feat(spec2cdk): add isCfn<Resource> type guard methods to L1 resources Nov 29, 2025
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Nov 29, 2025
@mrgrain mrgrain changed the title feat(spec2cdk): add isCfn<Resource> type guard methods to L1 resources feat(aws-cdk-lib): all L1s now have a isCfn<ResourceName> static helper to check if a value is this L1 resource Nov 29, 2025
Copy link
Copy Markdown
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(This review is outdated)

@mrgrain mrgrain added pr-linter/exempt-readme The PR linter will not require README changes pr-linter/exempt-integ-test The PR linter will not require integ test changes labels Nov 29, 2025
@aws-cdk-automation aws-cdk-automation dismissed their stale review November 29, 2025 13:46

✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.

@aws-cdk-automation aws-cdk-automation added the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Nov 29, 2025
@mrgrain mrgrain self-assigned this Nov 29, 2025
@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Dec 1, 2025

Merge Queue Status Beta

✅ The pull request has been merged

This pull request spent 2 hours 1 minute 11 seconds in the queue, including 48 minutes 14 seconds waiting for CI.
The checks were run in-place.

Required conditions to merge

@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Dec 1, 2025

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation aws-cdk-automation removed the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Dec 1, 2025
@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Dec 1, 2025

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Dec 1, 2025

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify mergify bot merged commit dc9db9b into main Dec 1, 2025
16 of 17 checks passed
@mergify mergify bot deleted the mrgrain/feat/isCfnX-method branch December 1, 2025 11:33
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Dec 1, 2025

Comments on closed issues and PRs are hard for our team to see.
If you need help, please open a new issue that references this one.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 1, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

contribution/core This is a PR that came from AWS. p2 pr-linter/exempt-integ-test The PR linter will not require integ test changes pr-linter/exempt-readme The PR linter will not require README changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants