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)
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?
Activity
yortus commentedon Jun 18, 2016
If you use the
--strictNullCheckscompiler option, you'll get a compiler error statingVariable 'a' is used before being assigned. Is that what you are after?benjaminmillhouse commentedon Jun 18, 2016
That probably would do it. Sorry, didn't see that in the tsconfig options. I'll give it a try.
yortus commentedon Jun 18, 2016
Benmillhouse it's only in the nightly version, so might not be documented yet. See #7140.