Avatar ·

How to properly parse a JSON string in TypeScript with typing

Hello everyone! I've just started learning TypeScript and encountered a problem when parsing JSON. I have a JSON string that I receive from the server, and I want to convert it into an object with correct types. Here's an example of the code I wrote: ```typescript const jsonString = '{"name": "John", "age": 30, "isActive": true}'; // Simple parsing const parsed = JSON.parse(jsonString); console.log(parsed.name); // Works, but TypeScript complains ``` The problem is that TypeScript doesn't know what type `parsed` is. It considers it `any`, and I lose all the benefits of typing. When I try to access the `parsed.name` property, the editor doesn't provide autocomplete, and I might accidentally write `parsed.neme` — the error won't be detected until runtime. I tried using interfaces