`JSON.parse` returns `any`, which silently disables type checking — a common source of runtime bugs when the actual JSON doesn't match assumptions. Assigning to `unknown` and validating before use is safer.
ts
interface Config { chainId: number; rpcUrl: string; }
function isConfig(value: unknown): value is Config {
return (
typeof value === "object" && value !== null &&
typeof (value as any).chainId === "number" &&
typeof (value as any).rpcUrl === "string"
);
}
function loadConfig(raw: string): Config {
const parsed: unknown = JSON.parse(raw);
if (!isConfig(parsed)) throw new Error("Invalid config");
return parsed; // narrowed to Config
}Libraries like zod or io-ts automate this pattern by deriving both a runtime validator and a static type from one schema, avoiding the duplication of writing an interface and a hand-written guard separately.