I was testing some code that utilizes objects in TypeScript and noticed that my IDE’s IntelliSense was throwing an error for a new property I was trying to add. It states that the property “text” does not exist, here is my code:
// create new object
var thing : Object = new Object();
// Do things
thing.text = "This is a test.";
console.log(thing.text);
// dereference the object
thing = null;
The error is highlighted on the line(s):
thing.text = "This is a test.";
console.log(thing.text);
Why does VS code list this as an error when this is perfectly acceptable code and behavior in JavaScript? Here is the error screenshot from my editor:
Error