TypeScript Simple Types

string, number, boolean and type inference.

✍️ 3 exercises + code challenge in this lesson

The basic types are string, number and boolean.

  • Explicit: let age: number = 25;
  • 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.

Free sign-in required · Google login available

to save your exercise progress.
Finished this lesson?
Mark it complete to track your progress.

Stuck on something?

Ask the community in the CodesInTech forum.

Need a developer?

Learning on your own is great — and when you need professional help, our team builds custom software, websites and mobile apps for clients worldwide.

Explore Our Services