Typescript, a superset of Javascript, requires that Javascript code must function in Typescript. However, when attempting to create class members in a typescript file using the same approach as Javascript, an error is encountered.
CODE :- script.ts (typescript file)
class App{
constructor(){
this.name = 'john';
}
}
let obj = new App();
console.log(obj.name);
Output : Property 'name' does not exist on type 'App'
Interestingly, this exact code works perfectly fine in a javascript file. The question remains - why does it not work in a typescript file??