Recently, as part of my learning journey with Angular, I encountered an intriguing issue. While working on my code, I noticed that the error popped up in my code editor (VSCode) but not when running the code in the browser.
The dilemma stemmed from setting a property to be interpreted as a string initially, only to update it to a number within the constructor. Here's a snippet of the code:
export class SandboxComponent{
name:string = 'John Doe';
constructor(){
this.name = 34;
}
}
You can view screenshots comparing how the code behaves differently in the browser versus VSCode: Browser View, VSCode View.
While VSCode correctly flags an error about assigning a number to a string, the browser seems to convert it without any issues. This discrepancy raises the question - why does the error show in VSCode but not affect the browser output?