Interview Q&A

Interview Q&A: ☕ If You Know Java: Interview Q Bridge Q2 covers interface vs type — but the bigger surprise for Java devs is HOW TypeScript interfaces work.

☕ If You Know Java: Interview Q Bridge

Q2 covers interface vs type — but the bigger surprise for Java devs is HOW TypeScript interfaces work. Java uses nominal typing (class must say 'implements'). TypeScript uses structural typing — any object with the right shape satisfies an interface automatically.

This is the most important TypeScript concept for Java devs. You rarely write "implements" in TS — if the shape matches, it satisfies the interface. Great for mocking in tests: just pass an object with the right methods.

Q7 covers generics — the good news: TypeScript generics look almost identical to Java generics. Same syntax, same extends constraints. Key difference: TypeScript adds union types and conditional types that Java doesn't have.

If you know Java generics, TypeScript generics will feel instantly familiar. The extra power (union types, infer, conditional types) comes naturally once you are comfortable with the basics.

Q10 covers readonly — Java developers know 'final' prevents reassignment. TypeScript 'readonly' is the compile-time equivalent. Key additions: Readonly utility type makes every property readonly at once, and 'as const' freezes literal values.

"readonly" = Java "final" for fields. "Readonly " = automatic final on all fields — no Java equivalent. "as const" freezes both the type AND the value — very useful for test status enums.

The locator matched no element or the element was not actionable within the timeout. Causes: wrong selector, element not yet rendered, element inside a different frame.

The locator matched more than one element. Playwright in strict mode expects exactly one element by default.

The browser context or page was already closed when the action was attempted. Usually caused by incorrect fixture teardown order or a previous test failure closing the page.

Connection to the target URL was refused. The application was not started before tests ran, or the port number is wrong.

The assertion timeout expired — the expected element was not visible within the timeout. Possible causes: animation delay, API response latency, or wrong selector.

A function expects an enum type but received a plain string. TypeScript does not automatically coerce strings to enum types.

Practice: Fix the "Why Is any Risky?" Interview Code Example