aws-lambda: `any` return types don't agree with strict ESLint rules
- Dominant language
- TypeScript
- Stars
- 12.9k
- Forks
- 4.6k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 83
Description
### Describe the bug
In some places `aws-cdk` returns `any` but this causes trouble for projects that forbid usage of `any` (e.g. via ESLint rules).
### Regression Issue
- [ ] Select this option if this issue appears to be a regression.
### Last Known Working CDK Version
_No response_
### Expected Behavior
Returns types are properly typed so as to not trigger any `any` assignment lint warnings/errors.
### Current Behavior
Some APIs return `any`.
### Reproduction Steps
```ts
lambda.addEventSource(
new DynamoEventSource(table, {
startingPosition: StartingPosition.LATEST,
filters: [
FilterCriteria.filter({
eventName: FilterRule.isEqual('EVENT_NAME'),
userIdentity: {
type: FilterRule.isEqual('TYPE'),
principalId: FilterRule.isEqual('PRINCIPAL_ID'),
},
}),
],
}),
);
```
the usages of `FilterRule.isEqual()` are flagged with the following error:
> Unsafe assignment of an `any` value. eslint[@typescript-eslint/no-unsafe-assignment](https://typescript-eslint.io/rules/no-unsafe-assignment)
### Possible Solution
Change the following in event-source-filter.d.ts from...
```ts
static isEqual(item: string | number | boolean): any;
```
to...
```ts
static isEqual(item: string): [string];
static isEqual(item: number): [{ numeric: ['=', number] }];
static isEqual(item: boolean): [boolean];
```
### Additional Information/Context
_No response_
### CDK CLI Version
2.161.0 (build be5ad8b)
### Framework Version
_No response_
### Node.js Version
v20.18.0
### OS
macOS Sonoma 14.7.1 (23H222)
### Language
TypeScript
### Language Version
5.6.2
### Other information
_No response_
Contributor guide
Research direction
Start with the `event-source-filter.d.ts` declaration mentioned in the issue and inspect the return type of `FilterRule.isEqual()`. Reproduce the reported unsafe-assignment warning in the provided `DynamoEventSource` example. Done when the return types no longer cause the reported lint error; the issue has had no comment for over 180 days.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, typescript
- Domain
- infrastructure
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100