react-ioc
react-ioc copied to clipboard
Property 'propName' is used before its initialization
Hello everyone!
I am using typescript 4.1.3 and I get this error Property 'propName' is used before its initialization.
I can fix it using "!", but I'm not sure how correct it is @inject propName!: propService.
Maybe someone can suggest something, thanks.
There is a few options to deal with it:
- Use not-null assertion when needed as you described in the subject.
- Turn off strictPropertyInitialization globally in your tsconfig.json. Turning off the checking globally may be considered as a bad practice, it's quite useful overall.
- Use
declareproperty modifier introduced in TS 3.7. Note that you have to use it whenuseDefineForClassFieldsis enabled (e.g. it's mandatory for MobX's decorators) as I reported in the sibling issue.