-
Notifications
You must be signed in to change notification settings - Fork 134
Document the use of ! for required props #232
Comments
Try adding "strictPropertyInitialization": false to your compiler options. |
@WangLarry in general, would not recommend turning off "strictPropertyInitialization". It's there to prevent a class from having a constructor that forgets to set each of the properties. But I suppose in Mongo/Mongoose, it might be easier to not have a constructor due to number of methods that exist on each class. So I suppose "strictPropertyInitialization" is not a good match for a Mongo/Mongoose project. @ctrlplusb but academically speaking, I think the correct way to correct the TS error is:
After you do that, then your class will always have a way of ensuring that name is set. As for the use of
|
I faced the same problem. I downgraded Typescript from 3.3.3 to 2.9.2 and the error is gone. But, I think, this is not how you want to solve this. |
@dgreene1 Wouldn't having a Imagine if |
It appears that when
strictPropertyInitialization
is enabled you need to add a ! to the definitions of any of your props that are "required" otherwise you will see a TS error similar to "Property 'foo' has no initialiser and is not definitely assigned in the constructor".e.g.
Related:
The text was updated successfully, but these errors were encountered: