Lesson 3 of 56 · Typescript
Primitive Types & Type Inference
Duration: 15 minutes
Primitive Types
TypeScript adds static types on top of JavaScript’s primitives.
let isReady: boolean = true;
let count: number = 42;
let name: string = "Alice";
let bigInt: bigint = 9007199254740991n;
let unknownVal: unknown = "maybe";
Type Inference
When you omit an explicit annotation, TypeScript infers the type from the initializer.
let inferred = 123; // inferred as number
let message = "hello"; // inferred as string
If you try to assign a value of a different type, the compiler will error:
inferred = "oops"; // ❌ Type 'string' is not assignable to type 'number'
The any type
let anything: any = 5;
anything = "now a string"; // OK, but you lose type safety.
Best practice: Avoid
any; preferunknownwhen you truly don’t know the shape.