#const data = await res.json() ! Unsafe assignment of `any` value

23 messages · Page 1 of 1 (latest)

pine adder
#

Is this working as intended? How are people fetching data with this eslint rule set to error?

zinc dune
#

First time seeing the rule, is there documentation for it?

#

Wild guess, try:

const data: unknown = await res.json()
pine adder
pine adder
#

I guess that package from that guy on youtube would fix it too... what's it called? Ts-reset?

#

that removes the baked in anys

zinc dune
#

Yeah that one works as well.

pine adder
#

seems pretty silly to have anything be any by default when unknown exists

zinc dune
#

Yeah I wish TS would just changed the anys in the few places they still use it.

pine adder
#

but I guess unknown didn't exist when they implemented it and they can't break peoples' stuff

pine adder
zinc dune
#

Yep, do keep in mind their warning about not using ts-reset in library code though.

pine adder
#

yeah I know about that

#

this component is actually going to be possible to npm install, but luckily it's been decided to depreciate that part of the system

#

guess I should do the unknown dance anyway to stay on the safe side

zinc dune
#

Do you have lots of raw fetch calls?

#

I find it that fetch is a bit too low level, and usually you would wrap it and expose a higher level API like fetchPeople etc, so you are really having to do data: unknown in those few places.

pine adder
#

just this one

#

well, I mean just this one wrapper like that

#

so it's not a problem, but it was a nice excuse to try ts-reset, which I've been meaning to do since I head about it

zinc dune
#

Removing anys from JSON.parse and res.json is probably the best thing yeah, the others are kind of 🤷‍♂️

pine adder
#

I didn't check the full list but yeah when I saw this error earlier after messing around with eslint config I felt a bit rustled