Object and empty object types
Concept and syntax
Lowercase object excludes primitive values and accepts objects such as arrays and functions. The empty object type {} accepts any non-nullish value under strictNullChecks; it does not require an object with no properties. Uppercase Object is a broad built-in interface and likewise accepts ordinary non-nullish primitives. Prefer a specific property shape when you need fields, or object when only non-primitive values make sense.
Working example
Compile standalone examples in a fresh directory with tsc --strict --target ES2022 --module commonjs --noEmitOnError main.ts, then node main.js.
const a: object = { count: 1 };const b: {} = 7;const c: Object = "tea";console.log(typeof a, typeof b, typeof c);Expected output (one line per log):
object number stringCommon mistake
Intentionally invalid; check this snippet separately. Do not run it.
Expected compiler diagnostic: TS2322. A primitive number is not assignable to lowercase object. Use number if the value really is numeric.
Practice and recap
Test assignments of an array, a string, and null to object and {} in separate snippets. Record which the checker accepts.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Object and empty object types — knowledge check
Check the concept, apply it to a new choice, and interpret a compiler diagnostic.
Which type excludes primitive numbers?
Does {} require a value with zero properties?
Why is this assignment rejected?
const a: object = 7;