You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It would seem like this is a (common?) bug that the compiler could catch for us.
Given this example class:
classFoo{bar: number;}
let a: Foo;a.bar=1;
At runtime I will get an error 'Cannot set property 'bar' of undefined because I never actually initialized the object. (i.e. let a: Foo = new Foo(); or let a = new Foo();)
This seems to me like it could probably be a pretty common developer mistake given the ability to provide types (: Foo), especially since editors will give you full Intellisense on the object just by naming the type of it without initialization. I'm curious if it's something that the Compiler could catch? (variable a is undefined; declared, but never initialized)
The text was updated successfully, but these errors were encountered:
If you use the --strictNullChecks compiler option, you'll get a compiler error stating Variable 'a' is used before being assigned. Is that what you are after?
It would seem like this is a (common?) bug that the compiler could catch for us.
Given this example class:
At runtime I will get an error 'Cannot set property 'bar' of undefined because I never actually initialized the object. (i.e.
let a: Foo = new Foo();
orlet a = new Foo();
)This seems to me like it could probably be a pretty common developer mistake given the ability to provide types (: Foo), especially since editors will give you full Intellisense on the object just by naming the type of it without initialization. I'm curious if it's something that the Compiler could catch? (variable a is undefined; declared, but never initialized)
The text was updated successfully, but these errors were encountered: