'Typescript error: Property [name] does not exist on Type [Object]

I am reading an Angular 9 book and the author has updates online for Angular 11. I started getting the error: "Property [name] does not exist on Type [Object]" for code like

let myData = new Object();
myData.name = "Adam";
myData.weather = "sunny";

Everyone seems to be saying to create an interface to fix this. But I am wondering if there is a simple way to turn this off in tsConfig.json so I can follow along with the examples in the book.



Solution 1:[1]

myData is an Object.

You can do one of these:

1.

let myData: any = new Object();
interface MyInterface {
  name: string;
  weather: string;
}

let myData: MyInterface = new Object() as MyInterface;
myData.name = "Adam";
myData.weather = "sunny";
class MyType {
  name: string;
  weather: string;
}

let myData2 = new MyType()
myData2.name = "Adam";
myData2.weather = "sunny"

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 zucker