All subjects

Programming · Interview subject

TypeScript Interview Questions

Types, interfaces and generics that keep a Playwright framework refactor-safe.

54 questions

Quick interview answer

Compile-time safety on page objects, API payloads and fixtures, real IDE autocomplete, safe refactoring, and typed test data that prevents whole classes of runtime failures.

Detailed explanation

Interfaces and generics let you type API responses so a renamed field breaks the build instead of a nightly run. Union types model test data variants, and strict null checks force explicit handling of optional elements. For frameworks, types are living documentation for page objects and fixtures; combined with path aliases and ts strict mode you get refactors that are mechanical rather than risky.

typescript
1interface Order { id: number; status: 'NEW' | 'PAID' | 'SHIPPED'; total: number }
2
3const order = await api.get<Order>('/orders/7');
4expect(order.status).toBe('PAID'); // typo in 'staus' fails at compile time

Real-world example

Typing API contracts caught a backend rename of total → amountTotal at build time, before the release run.

Interview tip

Frame types as failing earlier and cheaper — that is the argument managers buy.

Next subjectPlaywright