aws / aws/aws-cdk

cdk.Fn: improve conditionEquals parameters types

Open
#30,036 1 comment 0 reactions 0 assignees View on GitHub
@aws-cdk/core effort/small feature-request p2
Dominant language
TypeScript
Stars
12.9k
Forks
4.6k
Avg merge
2d 3h
Merged PRs (30d)
83

Description

### Describe the feature

Because `cdk.Fn.conditionEquals` is expecting 2 parameters of type `any`

image

people can logically think that the following condition, which compares "string" with "string", should work

```js
cdk.Fn.conditionEquals(props.createBucketParameter.valueAsString, "true"),
```

However, it does not. The proper way to configure this condition is to pass `CfnParameter` reference as follows,

```js
cdk.Fn.conditionEquals(props.createBucketParameter, "true"),
```

which leads to this template piece:

image

At first, this behavior seems illogical, because:

1. when reading a code that isn't using `asValueString`, the comparison is clearly between "CfnParameter" and "string" types, which, because of the lack of proper type definition for parameters, won't be considered as an option

2. the types in the `conditionEquals` method are of "any", which can make people think that they must compare similar types, like string and string, boolean and boolean, or even CfnParameter to CfnParameter. However, as shown previously, when using the type CfnParameters, the first argument must be its reference and not its`valueAsString`.

### Use Case

Developers will clearly know what types can be compared in `cdk.Fn.conditionEquals` when writting or reading code, which improves DX, and therefore efficiency.

### Proposed Solution

Add all type permutations that are possible for those 2 parameters in `cdk.Fn.conditionEquals`

### Other Information

_No response_

### Acknowledgements

- [X] I may be able to implement this feature request
- [X] This feature might incur a breaking change

### CDK version used

2.138

### Environment details (OS name and version, etc.)

macos

Contributor guide

Open the contributing guide

Research direction

Start by locating the TypeScript definition and implementation of cdk.Fn.conditionEquals, then inspect how CfnParameter references and valueAsString are currently typed. Use the examples in the issue to verify that the accepted parameter combinations reflect the behavior that produces the intended CloudFormation condition.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, typescript
Domain
infrastructure
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.