News for hackers. Stuff that matters.
Re:TypeScript 4.1 by Vinnl on Friday November 20, 2020 @03:04PM (#25164342)
Unfortunately no: that only errors when you do not add a type annotation and TypeScript can't infer anything better than `any`. JSON.parse(), however, is explicitly annotated to return any. See [1].

[1] https://www.typescriptlang.org/play?#code/PTAEEkDsDMFMCd6wCa...

Re:TypeScript 4.1 by WorldMaker on Friday November 20, 2020 @06:26PM (#25166381)
Yes, the type signature for JSON.parse() isn't inferred/deduced, it's explicit in lib.es5.d.ts (imported from lib.d.ts):

https://github.com/microsoft/TypeScript/blob/master/lib/lib....

You could provide your own lib.d.ts with `unknown` type returned for JSON.parse. I'm almost surprised there isn't a standard stricter lib.d.ts, though I suppose that linters fill enough of those needs with their rulesets.

Looking at GitHub issues surrounding it, it doesn't appear that there has been an explicit ask to switch the type signature to use `unknown`, probably the next closest was this one, where `unknown` is mentioned in a comment as a possibility but the comment is not addressed in follow up discussion: https://github.com/microsoft/TypeScript/issues/26993

It would be a big breaking change though at this point, so they would probably be hesitant to do so. I thought I saw somewhere there was a proposal to add it as a compiler flag to treat all uses of `any` in lib.d.ts as `unknown`, but I have no idea what happened to that proposal and quick searches don't turn up anything.

Re:TypeScript 4.1 by Vinnl on Saturday November 21, 2020 @06:32AM (#25169109)
Yeah I'd swear I'd seen that too, but I can't find it quickly either.
Re:TypeScript 4.1 by TheCoelacanth on Friday November 20, 2020 @07:38PM (#25166848)
Ah, I see my mistake. I have been getting warnings about JSON.parse, but they are coming from eslint@typescript-eslint/no-unsafe-assignment. It partially serves this purpose, but probably not as comprehensively as actually having it return unknown would.