Description
Use case
Behind the scenes, javascript converts numeric keys to strings. The pattern object[1234]
is valid. However, JSONObject is defined as [key: string]: JSONValue
and the result of getMultiple (dynamodb provider) cannot be cast into a type like [key: number] : JSONValue
since string
cannot be narrowed to number
.
The type being used expects it to be a number, because that is how the parameter is accessed.
You can do object[1234]
today without this change because TypeScript knows about the behavior of numbers being converted to strings. This is simply about narrowing the type to only allow numbers.
Solution/User Experience
Update JSONObject to the following type: type JSONObject = { [key: string | number]: JSONValue; }
This way a type can narrow JSONObject
to [key: number]:JSONValue
.
Alternative solutions
No response
Acknowledgment
- This feature request meets Powertools for AWS Lambda (TypeScript) Tenets
- Should this be considered in other Powertools for AWS Lambda languages? i.e. Python, Java, and .NET
Future readers
Please react with 👍 and your use case to help us understand customer demand.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status