Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(cli): cli import code never reaches "??" operator (#28113)
We're seeing this linter error flag: `Warning: G] The "??" operator here will always return the left operand [suspicious-nullish-coalescing]` in the yarn upgrade [task](https://github.com/aws/aws-cdk/actions/runs/6958118087/job/18935111755). It is because `const defaultValue = typeof resourceProps[idProp] ?? '';` never reaches the `??` since `typeof` returns a string (returns `"undefined"` when the type its looking at is `undefined`). The code in question is buggy, but also ambiguous in meaning. It could mean: `const defaultValue = typeof (resourceProps[idProp] ?? '');`, which means that we want `defaultValue === 'string'` when `resourceProps[idProp] === undefined`. or `const defaultValue = resourceProps[idProp] ? typeof resourceProps[idProp] : '';`, which means that we want `defaultValue === ''` when `resourceProps[idProp] === undefined`. Later on we use `defaultValue` as the condition in a ternary operator. This tells me that the latter is the correct way to interpret the code's intention, since `''` evaluates to `false`. All other options, including `'string'` and `'undefined'`, evaluate to `true`. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
- Loading branch information