Both describe object shapes and are mostly interchangeable. Interfaces can be reopened through declaration merging and extended with extends; type aliases can name any type, including unions, tuples, primitives, mapped and conditional types. Many teams use interfaces for object contracts and types for everything else.
Full answer with examplesInterview questions / Languages
TypeScript Interview Questions
TypeScript is the default for Playwright and modern Cypress projects. Interviewers check whether you can type page objects, fixtures and API responses safely.
5 questions · 2 beginner· 2 intermediate· 1 advanced
beginner questions
Partial, Required, Pick, Omit, Record, Readonly, ReturnType and Awaited derive new types from existing ones, so test data builders, API payloads and config stay in sync with the source types. For example Omit<User, 'id'> for a create payload, or Partial<User> for builder overrides.
Full answer with examplesintermediate questions
Explain any, unknown and never. When should you use each?
intermediate 2–5 yrs
any switches off type checking and spreads silently. unknown accepts any value but forces you to narrow it before use, which makes it the safe type for JSON, caught errors and external input. never is the type with no values, used for impossible states and exhaustive checks on unions.
Full answer with examplesHow would you use generics to build a typed API client for tests?
intermediate 2–5 yrs
Write request helpers like get<T>(path): Promise<T> so callers state the expected response type, or better, map endpoints to request and response types in one interface and use keyof plus indexed access types so the path determines the types. Remember generics are compile-time only: validate at runtime too.
Full answer with examplesadvanced questions
Types are erased on compilation, so res.json() as User is a cast, not a check. Validate at the boundary with a schema library such as Zod or JSON Schema with Ajv, infer the static type from the schema so there is one source of truth, and fail the test with a readable error when the contract drifts.
Full answer with examples