🎉 TypeScript Types Overview
Explore the core type system in TypeScript, which enhances JavaScript with static typing for better code reliability and maintainability.
📌 Key Type Categories
- Primitive Types:
number
,string
,boolean
,symbol
,null
,undefined
,any
,void
- Composite Types:
- Arrays: Use
[]
orArray<T>
syntax (e.g.,string[]
) - Tuples: Fixed-length arrays with specific types (e.g.,
[string, number]
) - Objects: Type annotations for properties (e.g.,
{ id: number, name: string }
)
- Arrays: Use
- Union/Intersection Types: Combine types with
|
(union) or&
(intersection)
📘 Recommended Reading
For deeper insights, check out our TypeScript Basics Tutorial to understand how types improve code quality.
🔍 TypeScript Type Examples
let age: number = 25;
let name: string = "TypeScript";
let isActive: boolean = true;
let items: (string | number)[] = ["apple", 1, "banana", 2];
type Point = { x: number; y: number };
💡 Pro Tip: Use the typeof
operator or tools like TypeScript Playground to experiment with types dynamically!