Inferred: let city = "Lahore"; — TypeScript knows it is a string.
Assigning the wrong type is a compile error: age = "old"; fails.
Special types
any turns type checking off (avoid it).
unknown is a safe "any": you must check the type before use.
never is for values that never happen.
💡 Key Takeaways: TypeScript Simple Types
Mastering TypeScript Simple Types helps you write clean and reliable TypeScript code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.
TypeScript Simple Types Code Example
TypeScript
let age: number = 25;
let city = "Lahore"; // inferred as string
let active: boolean = true;
age = age + 1;
console.log(age, city, active);
Output
26 Lahore true
Free sign-in required · Google login available
TypeScript Simple Types Practice Exercises
Check what you learned in “TypeScript Simple Types”.
/ 3 solved
Fill in the blank
Declare a boolean variable.
let isOpen: = true;
✓ Correct!Not quite. Try again.
Multiple choice
Which type is a safe alternative to any?
✓ Correct!Not quite. Try again.
Code challenge
Declare price: number = 1500 and qty: number = 3, then log their product.
Write the code in the live editor. Your answer is checked automatically.