TypeScript interview questions
12 questions, easy to hard. Read one, then answer it out loud: an AI interviewer follows up, hints when you're stuck and grades your answer.
TypeScript interviews test how you use the type system to catch bugs: unions and narrowing, generics, utility types and typing real code.
TypeScript
A colleague says that since the project moved to TypeScript, the app can't crash with a type error any more. Explain what TypeScript actually checks, when it checks it, and what it can't protect you from.
What a strong answer covers
- When TypeScript's checks happen and what's left by the time code runs.
- How much it works out without annotations.
- Which data it can't vouch for, because it arrives while the app is running.
- The ways developers can switch checking off, knowingly or not.
Common mistake: Believing TypeScript checks values while the app runs, and so trusting outside data to match its declared type.
- Any, Unknown and Never
- easy
- Pro
A code review flags a function whose parameter is typed as any. Explain what any does, why unknown is usually the better choice for a value you don't know yet, and what the never type means.
What a strong answer covers
- What giving up on a value's type costs.
- A safer type for values you don't know yet, and what it makes you do.
- The type for something that can never exist.
- Sensible places to use each.
Common mistake: Swapping any for unknown and then immediately casting it away instead of narrowing it.
- Model Shapes with Unions
- easy
- Pro
An app draws circles, which have a radius, and rectangles, which have a width and a height. Explain how you'd type a shape so that a function computing the area can only read the fields that exist for each kind, and so the compiler warns you if someone adds a triangle and forgets to handle it.
What a strong answer covers
- Giving each kind of shape its own type and combining them.
- A shared field that tells the compiler which shape it's looking at.
- How branching on that field limits each branch to the right fields.
- Making a forgotten new shape a compile error rather than a runtime surprise.
Common mistake: Using one type with every field optional, so the compiler can't tell which fields exist for which shape.
- Type Inference
- easy
- Pro
A new teammate adds type annotations to every single variable, even ones assigned a number literal, and asks whether that's best practice. Explain how TypeScript infers types, where annotations add value, and where they're just noise.
What a strong answer covers
- What TypeScript works out from values and return statements.
- Where there is nothing to infer from, so annotations are needed.
- Where explicit types pay off by catching mistakes early.
- Cases where inference gives a wider or narrower type than you might expect.
Common mistake: Annotating everything, including obvious literals, which adds noise and can widen types needlessly.
- Optional and Nullable Values
- easy
- Pro
With strict mode turned on, the compiler complains that a user's address might be undefined when you read the city. A colleague silences it with an exclamation mark. Explain what the compiler is warning about, and better ways to handle it.
What a strong answer covers
- What strict null checking is actually warning about.
- Why silencing the warning doesn't remove the risk.
- Ways to handle the missing case that the compiler understands.
- When the better fix is to change the type itself.
Common mistake: Using the non-null assertion as a quick fix, which hides the crash until it happens in production.
- Interfaces or Type Aliases
- easy
- Pro
A code review asks why some object shapes in the project are interfaces and others are type aliases. Explain the differences, what each can do that the other can't, and what convention you'd suggest.
What a strong answer covers
- What both can do when describing object shapes.
- Things only type aliases can express.
- A behaviour unique to interfaces that can help or surprise.
- A sensible team convention, and how much the choice really matters.
Common mistake: Treating the choice as a major design decision, when consistency matters more than which one you pick.
- Write a Generic Function
- medium
- Pro
You want a function that returns the first item of an array. Called with an array of numbers it should return a number, and with an array of users it should return a user, with no casting. Then you want a second function that reads a property from an object by name, where the compiler rejects property names that don't exist. Explain how you'd type both.
What a strong answer covers
- Letting a function's return type follow the type of what's passed in.
- Why callers rarely need to spell out the type parameter.
- Restricting a parameter to the property names that actually exist.
- Why this beats giving up on types with any.
Common mistake: Typing the result as any or casting at the call site, which throws away the safety generics give.
- Partial, Pick and Omit
- medium
- Pro
You have a User type with an id, a name, an email, a password hash and a creation date. You need three related types: the fields a user may change in an update, where every field is optional and the id can't be changed; the public profile, with only the id and name; and the input for creating a user, with everything except the id and the creation date. Explain how you'd define them without copying fields by hand.
What a strong answer covers
- The built-in utility types for making fields optional, keeping some or leaving some out.
- Combining them to build each of the three types.
- Why deriving types from one source beats copying fields by hand.
- How this stops sensitive fields reaching the wrong type.
Common mistake: Copying the fields into new hand-written types that drift as soon as the main type changes.
- Narrow with Type Guards
- medium
- Pro
A function accepts either a string, a list of strings or an error object, and needs to handle each differently. Explain how TypeScript narrows a union type inside your checks, and how you'd write your own reusable type guard.
What a strong answer covers
- The built-in checks TypeScript understands for narrowing a union.
- Other ways to tell members of a union apart.
- Writing a reusable check the compiler will trust.
- The risk that comes with that trust.
Common mistake: Writing a custom guard that checks too little, so the compiler believes a type that isn't true at runtime.
- Readonly and As Const
- medium
- Pro
A config object lists the allowed user roles, but functions accept any string as a role, and somewhere the list is accidentally modified. Explain how readonly types and the as const assertion would help, and how you'd derive the role type from the list.
What a strong answer covers
- How as const changes the types TypeScript gives a literal value.
- Deriving a type of allowed values from the list itself.
- Signalling and enforcing that a function won't change what it's given.
- Where compile-time readonly stops and runtime protection begins.
Common mistake: Writing the list of roles and a separate union type by hand, so the two fall out of sync.
- Type an API Response Safely
- hard
- Pro
Your app fetches a list of products from a third-party API. The current code parses the JSON and casts it to an array of products. One day the API starts returning prices as strings, and the app shows wrong totals without any error. Explain why the types didn't catch this, and how you'd make the boundary safe so bad data is caught where it enters the app.
What a strong answer covers
- Why a cast didn't protect the app from the changed data.
- Checking outside data when it enters the app.
- Keeping the runtime check and the static type from drifting apart.
- Deciding what to do when data doesn't match.
Common mistake: Believing that declaring the response type is the same as checking it.
Your team has a large JavaScript codebase and wants to move to TypeScript without stopping feature work. Explain how you'd plan the migration, which compiler settings you'd start with, and how you'd tighten them over time.
What a strong answer covers
- Converting gradually while features keep shipping.
- Starting with lenient compiler settings and tightening them over time.
- Dealing with libraries and code that have no types yet.
- Locking in progress and measuring how far there is to go.
Common mistake: Switching on every strict option at once, burying the team in errors and stalling the migration.
Questions about practising
- How should I prepare for typescript interview questions?
- Practise answering them out loud, not just reading them. Explaining an answer under follow-up questions is what interviews test. Work through the 12 questions here from easy to hard, and revisit the ones you struggle with.
- Can I practise typescript interview questions with an AI?
- Yes. Open any question and start a voice session: an AI interviewer asks it, follows up on your answer, gives hints when you're stuck and grades your answer with written feedback when the call ends.
- Are these typescript interview questions free?
- 1 of the 12 questions are free to practise. Sign in with Google, no card needed. Pro unlocks the rest, plus practice calls to your phone.