In essence, TypeScript has three intricate types: Object , {} and object .
object Contains material that is present in all JavaScript objects. Any value (primitive, not primitive, zero, etc.) can be assigned the type Object .
{}
{} is an empty object. This is the same as Object .
an object
object was introduced in TypeScript 2.2 . This is any non-primitive type . You cannot assign it any primitive type, for example bool , number , string , symbol , null and undefined
Thus, if you try this:
var strictTypeHeaders: { [key: string]: string } = {};
You will get a compilation error in the last line. This is because the type { [key: string]: string } more specific than the type object . There is no error in header = strictTypeHeaders , since both types are not primitive, and object is a more common type than { [key: string]: string }
source share