liveBook · Manning

TypeScript

As explained in Acing the Frontend Interview

TypeScript is a statically typed superset of JavaScript that adds compile-time type checking and related language features.

TypeScript adds a static type system to JavaScript. It catches type errors during development and supports autocompletion, navigation, and type-aware refactoring. In a large UI or backend codebase, types can also document contracts for teammates. An interview answer should connect these features to fewer debugging surprises, safer changes, and maintainability—not just say that TypeScript has types. section 3.6

A practical answer should be ready for these follow-up questions:

  • How do you keep an API flexible without giving up safety? Use generics to preserve a caller’s type information; unlike any, they do not bypass type checking. Constraints such as T extends User or K extends keyof T limit which values or keys an operation accepts. section 3.8
  • How do you work safely with uncertain values? Narrow types with typeof, instanceof, control flow, or type guards. Prefer narrowing to unsafe assertions, and use strict compiler settings to expose mistakes. section 3.9
  • How does TypeScript work with JavaScript libraries? Declaration files (.d.ts) describe JavaScript APIs with types but contain no implementation, enabling checking and editor support when the implementation is not TypeScript. section 3.9

A reusable React component

A generic ListProps<T> contract pairs items: T[] with renderItem: (item: T) => JSX.Element. A List<User> can therefore pass each user to a renderer that expects User. The interview point is the relationship between the array and callback types: the component stays reusable without discarding type information. section 3.8

Listing 3.15 Generic List component
interface ListProps<T> { #A
  items: T[]; #B
  renderItem: (item: T) => JSX.Element; #C
}
const List = <T,>({ items, renderItem }: ListProps<T>) => (
  <ul>{items.map(renderItem)}</ul>
);
// Usage of the generic List component
interface User {
  id: number;
  name: string;
}
const users: User[] = [
  { id: 1, name: 'Alice' },
  { id: 2, name: 'Bob' }
];
const renderUser = (user: User) => <li key={user.id}>{user.name}</li>; #D
<List<User> items={users} renderItem={renderUser} /> #E

Inspect the generic List implementation and its User usage to see the same type parameter carried through props and rendering. section 3.8

Execution is a separate question from type checking. TypeScript has traditionally been transpiled to JavaScript with tools such as tsc. Node.js v22.6.0 introduced experimental type stripping behind a flag; v22.7.0 added a flag for transforming TypeScript-only syntax such as enums; and Node.js v23 enables type stripping by default. A separate Stage 0 JavaScript proposal explores optional, erasable type annotations—an emerging proposal, not an established JavaScript feature. section 3.11

How Acing the Frontend Interview covers it

How deep it goes
Explains benefits and works through generics, constraints, narrowing, declaration files, and configuration rather than stopping at a definition.
Examples
Uses a generic React list, constrained generic functions, and declaration-file interview questions to make type safety concrete.
What it assumes
Assumes JavaScript and web-development fundamentals while introducing the purpose of static typing and explaining generics through examples.
What you can do after
Practice/perform it by explaining TypeScript’s trade-offs and designing reusable typed APIs while recognizing common type-safety and tooling choices.
How it connects
Connects TypeScript to JavaScript interoperability, React components, generics, type guards, and strict compiler configuration.

Also explained in

Compare how 6 books explain TypeScript →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Acing the Frontend Interview. The section links point to the parts of the book it draws on.