Recruitment and knowledge question base. Filter, search and test your knowledge.
TypeScript is a statically typed superset of JavaScript that compiles to JS. It helps catch errors early and improves tooling with types and autocomplete.
any disables type checking for a value, which can hide bugs. Use it sparingly and prefer precise types.
void represents the absence of a return value and is commonly used for functions that return nothing.
never represents values that never occur, such as functions that throw or never return (infinite loops).
Union types allow a value to be one of several types (e.g., string | number). Use them when a value can legitimately have multiple types.
Intersection types combine multiple types into one that has all their members (A & B). Unions allow a value to be any one of the listed types.
Interfaces describe object shapes and can be extended/merged. Type aliases can represent primitives, unions, intersections, and tuples. Use interfaces for public object contracts, type aliases for more flexible compositions.
Enums define a set of named constants (numeric or string). Use them for a closed set of values where readability matters.
Tuples are fixed-length arrays with known types at each position (e.g., [string, number]).
Type inference is the compiler’s ability to determine types from context without explicit annotations.
You mark a property with ? to make it optional (e.g., name?: string). It may be present or undefined.
Use the readonly modifier on properties or Readonly<T> utility type to prevent reassignment.
They allow a variable to be only a specific string value or union of specific strings, acting like a constrained enum.
They build new string literal types by combining other literal types using template syntax (e.g., `user_${"id" | "name"}`).
A declaration file provides type definitions for existing JavaScript code or libraries without implementations.
Partial makes properties optional, Required makes them required, Readonly makes them immutable, Record maps keys to a type, Pick/Omit select or exclude fields.
You compile with tsc (TypeScript compiler). .ts is plain TypeScript, while .tsx allows JSX syntax for React.
tsconfig.json configures the TypeScript compiler. strictNullChecks treats null/undefined as distinct types and prevents using them where a value is required.
Type guards narrow a union type at runtime checks. typeof checks primitives, in checks properties, instanceof checks classes, and custom predicates return x is Type.
Generics let you write reusable functions, classes, and types that work with different types while preserving type safety (e.g., T, U). They avoid repetition and keep strong typing.