interview.practice
TypeScript for JavaScript Developers interview questions
Answer aloud before opening each explanation. Focus on the reasoning, not memorized wording.
0/8 saved answers | 8 questions shown
01What happens to TypeScript types at runtime?FoundationsBeginner
Model answer
They are erased when the code is compiled to JavaScript.
Why
Types guide static analysis but do not exist as runtime validation.
02When should you prefer inference over an annotation?InferenceBeginner
Model answer
When the value already makes the local type obvious.
Why
Inference reduces noise while annotations remain valuable at public boundaries.
03How do optional properties differ from properties containing undefined?ObjectsBeginner
Model answer
An optional property may be absent; a required property typed with undefined must still exist.
Why
The distinction matters when checking keys and constructing objects.
04What is narrowing?UnionsIntermediate
Model answer
Proving that a value has a more specific type through a runtime-safe check.
Why
TypeScript follows checks such as typeof, equality, in, and discriminant properties.
05Why is unknown safer than any?SafetyIntermediate
Model answer
Unknown requires validation or narrowing before use.
Why
Any disables checking and allows unsafe operations to spread.
06What problem do generics solve?GenericsIntermediate
Model answer
They make code reusable while preserving relationships between concrete types.
Why
A generic can return the same item type it receives without reducing it to unknown.
07What does never represent?Advanced TypesAdvanced
Model answer
A value that cannot occur.
Why
Never appears in functions that cannot finish and in exhaustive union checks.
08Do TypeScript types validate API data at runtime?ArchitectureAdvanced
Model answer
No. External data still requires runtime validation.
Why
Static types describe developer expectations; schemas must verify untrusted values.