Daniel Bark

← Back to blog

Published 2024-10-09 by Daniel Bark

0
0

Why Typescript has 3 Object types

Object

Object represents the properties common to all JavaScript objects.

Some of the common properties it includes are toString() and valueOf().

{}

The {} type describes an object with no members of its own. This means TypeScript will raise an error if you try to access any property members of an object typed as {}.

For example:

let obj : {} = {};
console.log(obj.customProp); // TypeScript error: Property 'customProperty' does not exist on type '{}'.

object

The lowercase object type represents any non-primitive type. Meaning a type that is not one of the following: undefined, null, string, number, boolean, bigint and symbol.

Written by Daniel Bark

← Back to blog