Typescript Unsafe Assignment of An Any Value ESLint Error

Viewed 14622

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!

2 Answers

I got it.

let payload: unknown;

Tests pass for eslint as a result.

Related