Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core):
isTaggable
function can return undefined instead of false (
#31600) Closes #26495 ### Reason for this change The `isTaggable` function of the `TagManager` class is currently broken in Python, as it can return `undefined` instead of `true` or `false`. ### Description of changes In JS/TS, the logical AND operator (`&&`) returns the first falsy value it encounters, even if that value is `undefined` instead of `false` - so the current implementation of `isTaggable` allows for `undefined` to be returned if `tags` is undefined: ```ts public static isTaggable(construct: any): construct is ITaggable { const tags = (construct as any).tags; return tags && typeof tags === 'object' && (tags as any)[TAG_MANAGER_SYM]; } ``` The fix is simply changing the return line to the following to handle cases where tags is `null` or `undefined`: ```ts return tags !== undefined && tags !== null && typeof tags === 'object' && (tags as any)[TAG_MANAGER_SYM]; ``` ### Description of how you validated changes Added a unit test to assert that `isTaggable` returns `false`, not `undefined` for a non-taggable Construct (and still returns `true` for a taggable construct). ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
- Loading branch information