- Services
- Case Studies
- Technologies
- NextJs development
- Flutter development
- NodeJs development
- ReactJs development
- About
- Contact
- Tools
- Blogs
- FAQ
Understanding TypeScript Types: Basics & Examples
Learn how to leverage TypeScript's type checking for more reliable and maintainable JavaScript code.
Understanding TypeScript Types: Basics and Examples

TypeScript has revolutionized the way we write JavaScript by introducing a powerful type system. As a developer who’s spent countless hours debugging JavaScript code, I can’t emphasize enough how TypeScript has made my life easier. Let’s dive into the fundamental types that make TypeScript so valuable.
The Building Blocks: Basic Types
When I first started with TypeScript, understanding the basic types was my foundation. These are the simplest yet most crucial elements you’ll work with:
Number
In TypeScript, all numbers, whether integers or decimals, are represented by the number type. Here’s how I use them in my daily coding:
let price: number = 99.99;let quantity: number = 42;let temperature: number = -5;
String
Strings are probably the most commonly used type in any programming language. In TypeScript, we can be explicit about our string declarations:
let firstName: string = "John";let message: string = `Hello, ${firstName}`;Boolean
The boolean type might seem simple, but it’s incredible how much clearer your code becomes when you explicitly declare boolean variables:
let isActive: boolean = true;let isLoggedIn: boolean = false;Working with Arrays and Tuples
Arrays are where TypeScript really starts to shine. I remember how many bugs I used to encounter with JavaScript arrays - TypeScript makes those a thing of the past:
let numbers: number[] = [1, 2, 3, 4, 5];let fruits: Array<string> = ["apple", "banana", "orange"];
The Power of Custom Types
One of my favorite features in TypeScript is the ability to create custom types. It’s like having a blueprint for your data:
type User = { id: number; name: string; email: string; isAdmin: boolean;};
let currentUser: User = { id: 1, name: "John Doe", email: "john@example.com", isAdmin: false};Union Types: Flexibility When You Need It
Sometimes we need variables that can hold different types of values. Union types are TypeScript’s elegant solution to this:
let statusCode: number | string = 200;statusCode = "OK"; // This is also validRemember, TypeScript’s type system is your friend. It might feel like extra work at first, but trust me - the peace of mind and productivity boost you get from catching errors at compile-time instead of runtime is absolutely worth it.

Conclusion
As you continue your TypeScript journey, you’ll discover that these basic types are just the beginning. The type system is incredibly rich and flexible, allowing you to express complex relationships between data in your applications. Start with these fundamentals, and you’ll be well on your way to writing more reliable and maintainable code.
สร้างเว็บไซต์ 1 เว็บ ต้องใช้งบเท่าไหร่? เจาะลึกทุกองค์ประกอบ website development cost อยากสร้างเว็บไซต์แต่ไม่มั่นใจในเรื่องของงบประมาณ อ่านสรุปเจาะลึกตั้งแต่ดีไซน์, ฟังก์ชัน และการดูแล พร้อมตัวอย่างงบจริงจาก Till it’s done ที่แผนชัด งบไม่บานปลายแน่นอน
Next.js สอน 14 ขั้นตอนเบื้องต้น: สร้างโปรเจกต์แรกใน 30 นาที เริ่มต้นกับ Next.js ใน 14 ขั้นตอนเพียงแค่ 30 นาที พร้อม SSR/SSG และ API Routes ด้วยตัวอย่างโค้ดง่าย ๆ อ่านต่อเพื่อสร้างโปรเจ็กต์แรกได้ทันทีที่นี่
วิธีสมัคร Apple Developer Account เพื่อนำแอปขึ้น App Store ทีละขั้นตอน อยากปล่อยแอปบน App Store ระดับโลก มาอ่านคู่มือสมัคร Apple Developer Account พร้อมเคล็ดลับ TestFlight และวิธีอัปโหลดที่ง่ายในบทความเดียวนี้ได้เลย
TypeScript Interface คืออะไร? อธิบายพร้อมวิธีใช้และข้อแตกต่างจาก Type เรียนรู้วิธีใช้ TypeScript Interface เพื่อสร้างโครงสร้างข้อมูลที่ปลอดภัยและเข้าใจง่าย พร้อมเปรียบเทียบข้อดีข้อแตกต่างกับ Type ที่คุณต้องรู้ ถูกรวมเอาไว้ในบทความนี้แล้ว
Material-UI (MUI) คืออะไร อยากสร้าง UI สวยงามและเป็นมืออาชีพในเวลาอันรวดเร็วใช่ไหม มาทำความรู้จักกับ Material-UI (MUI) ที่ช่วยให้คุณพัฒนาแอปพลิเคชันบน React ได้ง่ายและดูดีในทุกอุปกรณ์
เปรียบเทียบ 3 วิธีติดตั้ง install node js บน Ubuntu: NVM vs NodeSource vs Official Repo แบบไหนดีที่สุด? เรียนรู้วิธีติดตั้ง Node.js บน Ubuntu ด้วย NVM, NodeSource หรือ Official Repo เลือกวิธีที่เหมาะกับความต้องการของคุณ พร้อมเปรียบเทียบ เพื่อการพัฒนาที่มีประสิทธิภาพ! Talk with CEO
We'll be right here with you every step of the way.
We'll be here, prepared to commence this promising collaboration.
Whether you're curious about features, warranties, or shopping policies, we provide comprehensive answers to assist you.