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
In the code below, removing the quotes from the instance field name triggers the expected compile-time error. I thought that maybe quoted fields are not checked, but apparently strictNullChecks works on quoted fields, so i think strictPropertyInitialization should work too.
Ok, now I see it was intended. But I don't see why it was decided to do it this way. It's easy for this kind of bug to sneak into the code, as setting strictPropertyInitialization makes the developer feel he is safe, when in fact he isn't.
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.
In the code below, removing the quotes from the instance field name triggers the expected compile-time error. I thought that maybe quoted fields are not checked, but apparently strictNullChecks works on quoted fields, so i think strictPropertyInitialization should work too.
TypeScript Version: 2.7.2
Search Terms: strictPropertyInitialization
Code
Expected behavior: error: Property 'field' has no initializer and is not definitely assigned in the constructor.
Actual behavior: compiles fine, crashes at runtime due to undefined field
Playground Link: https://www.typescriptlang.org/play/#src=class%20Example%0A%7B%0A%20%20%20%20public%20%22example%3Afield%22%3A%20string%3B%0A%7D%0A%0Aconsole.log(new%20Example()%5B%22example%3Afield%22%5D.toLowerCase())%3B
Related Issues:
The text was updated successfully, but these errors were encountered: