You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is just an implicit coercion, not anything JSON.parse does.
Literally false, see the spec step 1: Let jsonString be ? ToString(text) which explicitly converts text arg to it's string representation before doing anything else
But I still think the original comment has some point. It should not be a TS error to pass a Buffer to JSON.parse() since it’s pretty valid. Yes it’s an implicit coercion but it does make sense to use it there. Though I don’t know how you could patch this properly. It should still work in an ideal world.
If you have a raw Buffer you don't know if it's UTF-8, UTF-16, base64, etc.. Arguably the entire point of TS is to tell you when you're making assumptions like that.
Activity
IllusionMH commentedon Jul 8, 2021
Same as #17203 and moreover
Bufferis Node specific type and doesn't looks like it belongs to standard lib files.RyanCavanaugh commentedon Jul 8, 2021
This is just an implicit coercion, not anything
JSON.parsedoes.qwelias commentedon Dec 2, 2023
Literally false, see the spec step 1:
Let jsonString be ? ToString(text)which explicitly convertstextarg to it's string representation before doing anything elseRyanCavanaugh commentedon Dec 2, 2023
I'm curious what you think an implicit coercion is?
qraynaud commentedon Sep 11, 2024
Everything you said is true.
But I still think the original comment has some point. It should not be a TS error to pass a Buffer to
JSON.parse()since it’s pretty valid. Yes it’s an implicit coercion but it does make sense to use it there. Though I don’t know how you could patch this properly. It should still work in an ideal world.RyanCavanaugh commentedon Sep 11, 2024
If you have a raw
Bufferyou don't know if it's UTF-8, UTF-16, base64, etc.. Arguably the entire point of TS is to tell you when you're making assumptions like that.