Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Property 'propName' is used before its initialization #17

Open
GromovRoman opened this issue Dec 30, 2020 · 1 comment
Open

Property 'propName' is used before its initialization #17

GromovRoman opened this issue Dec 30, 2020 · 1 comment

Comments

@GromovRoman
Copy link

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.

@kirilldronkin
Copy link

kirilldronkin commented Jul 5, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants