TypeScript Coding Interview Tips
TypeScript coding interviews add a layer: types can clarify your thinking—or eat the clock when you fight the compiler. The goal is pragmatic typing: enough to communicate intent and catch real mistakes, not a perfect domain model mid-pad.
These TypeScript coding interview tips cover annotation strategy, speed habits, and freeze recovery when type errors pile up.
What interviewers usually want
- Correct algorithm and clear narration
- Types that match the prompt’s data shapes
- Avoidance of reckless
anywithout comment - Ability to model unions when the problem needs them
- Composure when the compiler complains
They rarely want advanced conditional types in a 45-minute algorithm round. Adjust if the role is heavily TS/frontend-platform—then expect more modeling.
First five minutes
- Restate the problem and examples
- Define input/output types from the prompt
- Sketch a short plan in comments
- Implement with straightforward types
- Tighten types only if they unlock clarity
Talk track:
“I’ll type the input as X and output as Y, then implement the hash-map approach.”
If the starter file already exports types, reuse them—do not redefine conflicting shapes.
Annotation strategy under time pressure
Do annotate:
- Function signatures you own
- Non-obvious object shapes
- Union states (
'loading' | 'ready' | 'error') in UI pads
Defer or keep light:
- Local variables the compiler already infers
- Fancy generics for one-off helpers
- Perfect narrowing in every branch on the first pass
If the pad is plain JS with TS optional, do not volunteer a type maze. Pragmatism reads as seniority more often than maximal typing does.
Useful everyday patterns
type Pair = [number, number];
interface Item { id: string; value: number }
function group(items: Item[]): Record<string, Item[]> {
const out: Record<string, Item[]> = {};
// ...
return out;
}
Prefer Record<string, V> or Map<K, V> deliberately—Maps are often clearer for non-string keys.
For optional fields: x?: number vs x: number | undefined—know the difference when reading prompts. For arrays that might be empty, decide whether T[] or a tuple better matches reality.
Compiler fights: triage order
When red squiggles appear:
- Read the error once—do not spam quick-fixes blindly
- Check whether your algorithm assumption is wrong (often it is)
- Add a narrow assertion only if you can justify it
- As a last resort, temporary
aswith a comment—then revisit
Talk track:
“The error says this might be undefined—I’ll guard before indexing.”
Guards beat assertions when time allows. If you assert, say what invariant makes it safe.
Algorithm pads in TS vs JS
Most classic DSA pads work like JS with types on the signature. Keep:
- Clarify → brute force → optimize
- Three-case dry-run
- Complexity out loud
Types should not change the algorithmic plan. If they do, you over-modeled. It is fine to implement in a slightly looser type and tighten at the end.
Frontend TS pads
- Prefer typed props on small components
- Controlled inputs:
ChangeEvent<HTMLInputElement>if you annotate handlers - State unions for UI modes
- Avoid prop-type theater while the feature is half-built
- Keep event handlers thin: update state, then render
Common pitfalls
- Using
anyto silence errors you do not understand - Overusing enums when string unions suffice
- Incorrectly typing nested arrays (
number[][]vs jagged) - Forgetting that
typeof null === 'object'in JS runtime checks - Spending ten minutes on utility types for a two-line helper
- Confusing
unknownandany(preferunknown+ narrowing when you must)
Freeze recovery
- Narrate the stuck point (algorithm vs type error)
- If algorithm: brute force in plain logic first
- If types: simplify signatures to the prompt’s shapes
- Make a visible progressive edit
- Re-run mental example
Separating “logic stuck” from “types stuck” prevents thrashing. Interviewers can help only if they know which bucket you are in.
Practice plan
| Session | Focus |
|---|---|
| 1 | DSA medium with explicit signatures only |
| 2 | Same + intentional undefined guard practice |
| 3 | Small UI pad with state union types |
| 4 | Timed pad: no any unless commented |
Soft practice note
If you want a Chrome side panel to rehearse calm narration and freeze recovery while you practice TypeScript pads, Luna Interview is built for that practice loop. Use it for composure under pressure—never as a substitute for learning TypeScript or for anything that violates interview rules.
Day-of checklist
- [ ] Input/output types named
- [ ] Plan commented
- [ ] Baseline logic correct
- [ ] Guards for undefined/null as needed
- [ ] Minimal assertions
- [ ] Three-case dry-run + complexity
Type enough to think clearly—then finish the problem.
Rehearse with an AI interview copilot, then browse commonly reported interview questions.