Recently, I'm confused about the difference between {} and Object. Sometimes, {} will solve my problem, sometimes, it can't and I switched with Object. I really don't know why.
I did some tests, hopefully, it can give you some hint.
const t: Array<{label: string}> = [{label:'1'}];
const arr: Array<{}> = t; //error
const arr2: Array<Object> = t; //pass
{} is an alias for new Object().
So you can say Object is a class and {} is an instance of that class.
You can see here:
console.log(JSON.stringify(new Object()) == JSON.stringify({}))
console.log({} instanceof Object)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With