Find: Wrong Strict Mode Config
Question
This code compiles without strict mode but errors with strictNullChecks. Find the issue:
Code
interface Config {
port: number;
}
const config: Config = JSON.parse("{}");
console.log(config.port);
Hint
JSON.parse returns any. What's actually in the parsed object?
Explanation
JSON.parse returns any, which bypasses type checking. The empty object {} has no port property, so config.port is undefined at runtime. With strict mode, the assignment from any to Config is allowed but the runtime behavior is wrong. Fix: validate the parsed JSON or use a runtime check: if (typeof config.port !== 'number') throw new Error('Invalid config');.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.