What is the difference between object, Object and {} in TypeScript?
object means any non-primitive (arrays, functions, plain objects). {} means any value that is not null or undefined, including primitives like 5. Object is the wrapper interface with toString and friends and behaves almost like {}. Prefer real shapes or Record instead.
Explain it simply
Think of three gates at a college fest. Gate one (object) lets in only things that are not simple values. Gate two ({}) lets in anything except nothing at all, so even the number 5 gets through. Gate three (Object) is the same crowd with a badge for methods like toString.
Because {} accepts strings and numbers, it is a poor way to say "some object". If you want "an object with any string keys", use Record<string, unknown>. If you know the fields, write them out.
Example
let a: object = { x: 1 };
a = [1, 2]; // OK: arrays are non-primitive
a = () => 1; // OK
// a = 5; // Error: number is not an object
let b: {} = 5; // OK: only null and undefined are rejected
b = "hello"; // OK
// b = null; // Error under strictNullChecks
let c: Record<string, unknown> = { id: 1, name: "Asha" }; // clearer intentWhat to say in the interview
"Lowercase object excludes primitives. {} excludes only null and undefined, so a number is assignable to it, which surprises people. Object is the wrapper interface and should be avoided. For a generic bag of properties I use Record<string, unknown>, and for known data I write an interface."
Common mistakes
- Using {} as a catch-all object type and being surprised that strings pass.