This is a way of declaring an Object, or you could say a dictionary, a key/value pair. Where you do not need to define the properties (different from an interface), you just say that the key will be of type string
and the value of type (in this case) string | string[]
.
So, when you set your headers as {'Accept': 'application/json'}
, for example, you are creating a pair where key is 'Accept'
, of type string, and this key's value is 'application/json'
, also of type string.
That way of declaring a type let's you have, of course, multiple dynamic properties, so you could end up with:
const headers = {
'Accept': 'application/json',
'Authorization': `Bearer ${jwt}`,
};