react-ioc icon indicating copy to clipboard operation
react-ioc copied to clipboard

Property 'propName' is used before its initialization

Open GromovRoman opened this issue 5 years ago • 1 comments

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.

GromovRoman avatar Dec 30 '20 06:12 GromovRoman

There is a few options to deal with it:

  1. Use not-null assertion when needed as you described in the subject.
  2. 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.
  3. Use declare property modifier introduced in TS 3.7. Note that you have to use it when useDefineForClassFields is enabled (e.g. it's mandatory for MobX's decorators) as I reported in the sibling issue.

kirilldronkin avatar Jul 05 '21 07:07 kirilldronkin