# Primitive Types — TypeScript

Source: https://www.geekswithgeeks.com/en/typescript/ts-primitives

> Annotating string, number and boolean values.

## string, number, boolean

A colon after the name declares its type. TS then enforces it everywhere.

```typescript
let name: string = "Ada";
let age: number = 36;
let isActive: boolean = true;
```

## Why annotate?

Once `age` is `number`, assigning a string to it is a **compile-time error**, not a runtime surprise months later.

## A type error

The compiler stops you right here — before the code ever runs.

```typescript
let age: number = 36;
age = "thirty-six";
// Error: Type 'string' is not assignable to type 'number'.
```

**Quiz:** What happens if you assign a `string` to a variable typed `number`?

- [ ] It works, JS is flexible at runtime
- [x] TypeScript throws a compile-time error
- [ ] The value silently converts to NaN

*Answer:* TypeScript throws a compile-time error. The TS compiler checks assignments against declared types and refuses to build mismatched code.
