One search. Connected ideas.
Find the lesson, understand the concept, and prepare your answer.
14 results shown · grouped by type
Technologies1
Use types to model data, narrow values, and build safer interfaces.
Lessons6
Interfaces and type aliases both describe types that TypeScript checks before runtime. An interface is mainly used for object contracts, while a type alias can name object shapes, unions, tuples and other type expressions. Choosing between them is mostly about the shape being modeled and whether declaration merging is needed.
Narrowing is TypeScript's process of reducing a broad type to a more specific type based on control flow and checks. A type guard is a check that gives the compiler evidence about a value, such as typeof, in or a custom predicate. Correct guards help application code safely use data that starts out uncertain.
A union allows a value to match one of several types, while an intersection requires it to satisfy all included types. keyof extracts property names from a type, and TypeScript's type-position typeof derives a type from a value declaration. Together they help express safe property access and reusable contracts.
Generics let a function, class or type work with different types while preserving relationships between inputs and outputs. Utility types transform existing types so the same fields do not need to be manually repeated. This reduces duplication without throwing away type information through any.
any allows operations without normal type checking, while unknown accepts any value but requires checks before use. never represents a situation where no value is possible, such as the result of a function that always throws. These types describe different levels of knowledge and should not be used interchangeably.
Mapped types build a new type by visiting the keys of another type, and conditional types choose a type based on a type relationship. Decorators are different: they run as part of JavaScript class definition and can add metadata or change behavior. Type transformations disappear during compilation, while decorator code can affect runtime behavior.
Interview questions6
Interfaces and type aliases both describe types that TypeScript checks before runtime. An interface is mainly used for object contracts, while a type alias can name object shapes, unions, tuples and other type expressions. Choosing between them is mostly about the shape being modeled and whether declaration merging is needed.
Narrowing is TypeScript's process of reducing a broad type to a more specific type based on control flow and checks. A type guard is a check that gives the compiler evidence about a value, such as typeof, in or a custom predicate. Correct guards help application code safely use data that starts out uncertain.
A union allows a value to match one of several types, while an intersection requires it to satisfy all included types. keyof extracts property names from a type, and TypeScript's type-position typeof derives a type from a value declaration. Together they help express safe property access and reusable contracts.
Mapped types build a new type by visiting the keys of another type, and conditional types choose a type based on a type relationship. Decorators are different: they run as part of JavaScript class definition and can add metadata or change behavior. Type transformations disappear during compilation, while decorator code can affect runtime behavior.
Generics let a function, class or type work with different types while preserving relationships between inputs and outputs. Utility types transform existing types so the same fields do not need to be manually repeated. This reduces duplication without throwing away type information through any.
any allows operations without normal type checking, while unknown accepts any value but requires checks before use. never represents a situation where no value is possible, such as the result of a function that always throws. These types describe different levels of knowledge and should not be used interchangeably.
Modules1
TypeScript learning module