Primitive Types
| Name |
Syntax |
Description |
|
|
string / number / boolean
TypeScript 1.0
|
let name: string = "Alice";
|
TypeScript's three basic primitive types. Type annotations are optional when the value is obvious (type inference).
|
Details →
|
|
any / unknown / never / void
|
let x: any let y: unknown function fn(): void
|
Special types: any disables type checking; unknown is type-safe any; never for functions that never return; void for no...
|
Details →
|
Complex Types
| Name |
Syntax |
Description |
|
|
interface
|
interface Name { property: type; method(): returnT...
|
Defines the shape of an object. Supports optional properties (?), readonly, and extension (extends).
|
Details →
|
|
type alias
|
type AliasName = TypeDefinition;
|
Creates a named type alias. Unlike interfaces, can alias primitives, unions, tuples, and mapped types.
|
Details →
|
|
Generics
|
function fn<T>(arg: T): T { return arg; }
|
Generics create reusable components that work with multiple types while maintaining type safety.
|
Details →
|
|
Union & Intersection types
|
type A = TypeX | TypeY type B = TypeX & TypeY
|
Union (|) means "one of these types"; Intersection (&) means "all of these types combined".
|
Details →
|
|
Enums
|
enum Direction { Up, Down, Left, Right }
|
Enums define a set of named constants. Numeric enums auto-increment; string enums are explicit.
|
Details →
|
Utility Types
| Name |
Syntax |
Description |
|
|
Partial<T> / Required<T>
|
Partial<Type> Required<Type>
|
Partial makes all properties optional; Required makes all properties required. Both create new types.
|
Details →
|
|
Pick<T, K> / Omit<T, K>
|
Pick<Type, "key1" | "key2"> Omit<Type, "key">
|
Pick selects a subset of properties; Omit excludes specified properties. Both create new types.
|
Details →
|
|
Record<K, V> / Readonly<T>
|
Record<KeyType, ValueType>
|
Record creates a type with specific keys and value types; Readonly makes all properties immutable.
|
Details →
|
Type Operators
| Name |
Syntax |
Description |
|
|
typeof / keyof / typeof
|
keyof Type typeof variable
|
keyof produces a union of a type's property names; typeof gets the type of a variable.
|
Details →
|
|
Type Guards / narrowing
|
if (typeof x === "string") if (x instanceof Date)
|
Type guards narrow the type within a conditional block, making TypeScript aware of the specific type.
|
Details →
|
No results found. Try a different search term.