0

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.

2
  • maybe disabling strict mode will help, try read this: stackoverflow.com/questions/57566377/… Commented Apr 27, 2022 at 12:47
  • How about let myData = {}; instead? Commented Apr 27, 2022 at 12:53

1 Answer 1

2

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"
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.