TypeScript is the standard for modern web application engineering. Evaluating a developer's TypeScript skills requires assessing their mastery of the compile-time type system, type safety patterns, and generic utilities.
1. type Alias vs interface
- •
interface: Best for object shapes and class contracts. Supports declaration merging (re-opening interfaces across files). - •
type: Alias for any type (primitives, unions, tuples, functions, objects). Does not support declaration merging.
interface User {
id: string;
name: string;type UserWithRole = User & { role: "admin" | "member" }; ```
2. Discriminated Unions (Tagged Unions)
Discriminated unions use a common literal property key to enable exhaustive type checking by the compiler.
type NetworkState =
| { status: "loading" }
| { status: "success"; data: string[] }function renderState(state: NetworkState) {
switch (state.status) {
case "loading":
return "Loading...";
case "success":
return Data items: ${state.data.join(", ")};
case "error":
return Error: ${state.error.message};
}
}
```
3. Built-in Utility Types
- •
Partial: Makes all properties optional. - •
Required: Makes all properties required. - •
Readonly: Makes all properties readonly. - •
Pick: Selects a subset of propertiesKfromT. - •
Omit: Removes propertiesKfromT. - •
Record: Constructs an object type with keysKand valuesT.
4. Custom Type Guards (is Keyword)
Type guards provide runtime checks that narrow types within conditional blocks.
function isString(val: unknown): val is string {
return typeof val === "string";function processInput(input: unknown) { if (isString(input)) { console.log(input.toUpperCase()); // TypeScript knows input is string } } ```
5. unknown vs any vs never
- •
any: Disables all type checking. Avoid in production code. - •
unknown: Type-safe counterpart toany. Requires type checking before property access or invocation. - •
never: Represents values that can never occur (e.g. function that throws or infinite loop).
---
Practice TypeScript Interviews Live Evaluate TypeScript candidates in a real-time collaborative Monaco environment with instant compilation. [Create a free Pairlet interview room](https://www.pairlet.dev/interview/new).
Frequently Asked Questions
What is the key difference between type aliases and interfaces in TypeScript?
Interfaces support declaration merging and are optimized for object shape extension. Type aliases are more versatile, supporting unions, primitives, tuples, and mapped types.
Conduct Live Coding Interviews with Zero Friction
No candidate sign-up required. Create an instant room, share the link, and code together in real time with shared code execution.