Closed
Description
Bug Report
π Search Terms
- property is used before its initialization
- esnext
- es2022
- before its initialization
π Version & Regression Information
- Does not seem to be a regression.
β― Playground Link
π» Code
class Foo {
bar = this.buz;
constructor(private buz: unknown) {}
}
π Actual behavior
TSC correctly produces the below compilation error when targeting ESNext. But does not when targeting ES2022.
TS2729: Property 'buz' is used before its initialization.
π Expected behavior
The same compilation error is shown when targetting ES2022.
Activity
Ozz760 commentedon Mar 18, 2023
Hello Alan,
I was wondering if I can take this issue?
alan-agius4 commentedon Mar 18, 2023
Go for it
Ozz760 commentedon Mar 21, 2023
Hello,
While I was researching this issue there were similar issue's that came up.
#45325
#45182
I'm not sure if this is consider as a duplicate.
Please let me know.
Thank you.
alan-agius4 commentedon Mar 21, 2023
Itβs not a duplicate as those issues are closed and problem still persists.
It appears that the problem was only fixed for esnext.
Dev79844 commentedon Apr 3, 2023
Hey Alan!
I would like to work on this issue if anyone is not working on it.
alan-agius4 commentedon Apr 4, 2023
@Dev79844, no one has opened a PR so far so feel free to open one.
Hazmi35 commentedon Apr 7, 2023
Can confirmed this issue is happening with
5.0.4
. Maybe related #50971 and #52331ES2022 (and above, including ESNext) implies
useDefineForClassFields: true
. TS2729 will happen if this option is set to true.On ESNext, if you set the option to true, TS2729 shows up, and when false it doesn't. This is expected.
But on ES2022, even with
useDefineForClassFields: true
explicitly set to true, there are no TS2729 errors.Anshul-target commentedon Apr 14, 2023
@alan-agius4 I am new to opensource could you suggest how would I test the error.
I have set up the project locally
alan-agius4 commentedon Apr 14, 2023
@Anshul-target, please see the contributing guidelines.
moheet333 commentedon Apr 23, 2023
Hey @alan-agius4 does the PR #53885 fix this issue?
alan-agius4 commentedon Apr 23, 2023
Looks like it