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





