Fairly new to Typescript and have this small block of code:
let payload;
if (event.body) {
payload = JSON.parse(event.body);
}
The payload line is throwing the below error from eslint:
Unsafe assignment of an any value. eslint(@typescript-eslint/no-unsafe-assignment
This is more of an exercise in understanding the intricacies with Typescript and eslint working together, what can I do to resolve this issue? Seems like a minor change would do the trick but I haven't been able to locate a preexisting question with the same intent. Thanks in advance for the help!
I got it.
let payload: unknown;
Tests pass for eslint as a result.
Found solution on the https://github.com/typescript-eslint/typescript-eslint/issues/2118
We can use external function to get data with set type of return like:
function(str: string): Superobj {
return JSON.parse() as Superobj
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With