How does TypeScript act as a “Safety Net” for JavaScript, and why is the any type considered a dangerous hole in that net?
TypeScript provides a safety net for JavaScript by using static type checking, allowing bugs to be detected before runtime. The any type is dangerous because it disables this checking for that variable, defeating TypeScript’s primary purpose.
When do you use type vs interface
You use interface for objects and extending, and type for everything else.
How do Generics (<T>) solve the problem of code duplication, and how do they differ from specific types?</T>
Generics act as “placeholders for types,” allowing you to write a single function or component that works safely with any type (e.g., a generic List). unlike specific types (e.g., string[]), they are not hard-coded; they capture the type provided at the time of use.
What is the practical difference between Numeric and String Enums, and why use a const enum?
Numeric: Default behavior (0, 1, 2). Harder to debug. String: More descriptive and easier to debug (value is readable text). const enum: A performance feature. It is completely removed during compilation, with values inlined into the code.
Why is tsconfig.json considered the “Brain” of the project, and what does the strict: true option specifically enforce?
The Brain: Its presence marks the project root and controls how TS compiles code (e.g., target version, module system). strict: true: Enables a suite of rigorous type-checking rules. It is considered non-negotiable for modern projects to ensure maximum safety.
What is the purpose of the include and exclude options in tsconfig.json?
They define the scope of the TypeScript project. * include: Specifies which files/directories strictly belong to the app (e.g., src/**/*). * exclude: Prevents TypeScript from trying to compile external libraries or build artifacts (e.g., node_modules, dist).