Q1
What is the critical safety difference between any and unknown inside TypeScript test automation and API wrappers?
any disables TypeScript type checking completely (letting res.foo.bar() fail silently at runtime). unknown accepts any parsed JSON value yet FORCES you to narrow/validate type (typeof, in, Zod) before accessing properties.
Q2
Why can interface Page { ... } and type Page = ... behave differently regarding Declaration Merging and Discriminated Unions?
interface declarations with the same name automatically merge (used by Express/Playwright module augmentation), whereas type aliases support discriminated unions (Result = Ok | Err), mapped types, and conditional tuple types.
Q3
How do Discriminated Unions + never exhaustiveness checks (const _check: never = state) catch missing test/UI cases at compile time?
Adding a tagged literal (kind: 'loading' | 'success' | 'error') lets TypeScript narrow fields automatically in switch, and assigning default: const _x: never = state causes an instant compile error whenever someone adds a 4th state later without updating handlers!
Q4
Why does tsconfig.json strictNullChecks: true catch half of production JavaScript crashes (Cannot read properties of undefined)?
Without strictNullChecks, null and undefined secretly inhabit *every* type (string, User), hiding missing null guards. Enabling it forces explicit User | undefined narrowing (?. or if (!user) throw).
Q5
What does TypeScript's satisfies operator solve that plain type annotations (const cfg: Record<string, Route> = ...) lose?
Typing cfg: Record<string, Route> widens away exact literal key autocomplete (cfg.home becomes nullable/loose). satisfies Record<string, Route> validates shape compliance *while preserving exact inferred literal key types*!
Q6
Why does keyof typeof MY_ENUM or as const objects often outperform TypeScript enum in modern codebases?
Numeric TS enum emits weird reverse-mapping objects at runtime and accepts arbitrary numbers without warnings! const STATUS = { OPEN: 'open', CLOSED: 'closed' } as const has zero runtime bloat and clean literal inference.
Q7
How do Generics (<T extends BaseEntity>) + Utility Types (Partial<T>, Pick<T, K>, Omit<T, 'id'>) keep API request/response test fixtures DRY?
Omit<User, 'id' | 'createdAt'> auto-derives valid Create payloads directly from the DB model type, while Partial<User> builds Patch overrides—automatically flagging test fixture breakage whenever backend schemas change.
Q8
Why does .catch((err) => err.message) fail under useUnknownInCatchVariables in strict TypeScript?
Any thrown value in JS could be a string, null, or custom object—not always Error. Strict TS types catch (err: unknown), requiring err instanceof Error ? err.message : String(err).
Q9
What subtle bug happens if you pass Object.keys(myObj) into .map((k) => myObj[k]) in TypeScript?
Because TypeScript objects allow extra structural subtyping properties at runtime, Object.keys() intentionally returns string[] rather than (keyof T)[]—preventing unsafe indexing errors.
Q10
Why does forgetting await inside test('checks status', () => { expect(api.get()).resolves.toBe(200); }) silently pass broken tests?
Returning or awaiting async assertions is mandatory—without await / return, Jest/Playwright finishes the synchronous callback immediately before the rejected Promise ever resolves! Enable @typescript-eslint/no-floating-promises.