Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(core): isCfnResource allows any type as input (#28001)
It is more or less frustrating that we have to check if a variable is undefined or not before calling the `CfnResource.isCfnResource` method. For example, ```ts const bucket1 = new Bucket(stack, 'Bucket1'); const bucket1Resource = bucket1.node.defaultChild; if (bucket1Resource !== undefined && // Currently we need this! cdk.CfnResource.isCfnResource(bucket1Resource) ) { bucket1Resource.addDependency(...); } ``` With this PR, `isCfnResource` now accepts `any` type as input and performs the necessary validations inside. ```ts const bucket1 = new Bucket(stack, 'Bucket1'); const bucket1Resource = bucket1.node.defaultChild; if (cdk.CfnResource.isCfnResource(bucket1Resource)) { // much smoother bucket1Resource.addDependency(...); } ``` Actually, other `isXxx` methods have consistent signatures like the one below: ```ts public static isStack(x: any): x is Stack public static isReference(x: any): x is Reference public static isCfnElement(x: any): x is CfnElement // and more... ``` This change also makes the `isCfnResource` consistent with these signatures. Note that this is not a breaking change, because the input constraint is relaxed, not tightened, so all the old code will work without change. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
- Loading branch information