Catalog / TypeScript Cheatsheet
TypeScript Cheatsheet
A comprehensive cheat sheet covering TypeScript syntax, types, and features, designed for quick reference.
Basic Types
Primitive Types
|
Represents
|
|
Represents numeric values (floating point numbers).
|
|
Represents a sequence of characters.
|
|
Represents an array of values of a specific type.
|
|
Represents an array with a fixed number of elements whose types are known.
|
|
A way of giving more friendly names to sets of numeric values.
|
Special Types
|
Represents a type that can be anything. Use when the type is not known.
|
|
Represents the absence of a type, usually for functions that do not return a value.
|
|
Represent
|
|
Represents the type of values that never occur. Used for functions that always throw an exception or never return.
|
Interfaces and Classes
Interfaces
Interfaces define contracts for objects. They specify the properties and methods an object must have.
|
Interfaces can also describe function types:
|
Classes
Classes are blueprints for creating objects. They contain properties and methods.
|
Classes can implement interfaces:
|
Access Modifiers
|
Functions
Function Types
Functions in TypeScript can be defined with named parameters and types.
|
Optional and Default Parameters
TypeScript supports optional and default parameters in functions.
|
Rest Parameters
Rest parameters allow you to pass a variable number of arguments to a function.
|
Function Overloads
Function overloads allow you to define multiple function signatures for the same function name.
|
Generics
Generic Functions
Generics allow you to write functions that can work with a variety of types without sacrificing type safety.
|
Generic Interfaces
You can also define generic interfaces.
|
Generic Classes
Generic classes are similar to generic interfaces.
|
Generic Constraints
You can constrain the types that a generic type parameter can be.
|