- "primitive":
boolean
,number
,string
,symbol
,null
,undefined
- "object" aka "non-primitive": any "custom object" (e.g.
{ foo: 1 }
) or function
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types
(In JS, people mistakingly think of primitives as "object"s, but in strict JS terminology, they're not.)
An "object" aka "non-primitive" (as per JS terminology above).
const myObject: object = primitive // error
const myObject: object = customObjectOrFunction // no error
The class instance behind any "object".
primitive instanceof Object // false
customObjectOrFunction instanceof Object // true
// At first glance, we would expect this to error, so that TS' behaviour matches
// JS's runtime behaviour. However, TS only cares about structures, so this does
// not error.
const myObject: Object = primitive;
const myObject: Object = customObjectOrFunction;
// Note: `Object` value === `ObjectConstructor` type
An object
but specifically one without any properties (TODO: correct?).
const myObject: {} = {}; // no error
// At first glance, we would expect this to error, but it doesn't. TODO: why?
const myObject: {} = { foo: 1 };
The biggest observable difference between
{}
andObject
is in type relationships. A{ toString: number }
is assignable to{}
, but notObject
.