You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Transpiled code works (bar is defined in the constructor as it's done for the downlevel emit) OR used-before-assignment error on this.foo in the initializer of bar.
Actual behavior:
Since the initializer of bar is run before the assignment of foo, there's a runtime error.
This code used to work for ages (of course without native class fields). A lot of code that uses dependency injection looks like this.
Related Issues:
I thought this was already discussed somewhere with @RyanCavanaugh and @sandersn, but I couldn't find an issue for that.
Found while looking at #36405. That PR would need an exception if parameter properties are involved IF you want to continue supporting the example code.
The text was updated successfully, but these errors were encountered:
Support for [[Define]] so far has given an error whenever code that used to work for [[Set]] is no longer valid. I think that an error with useDefineForClassFields: true is the correct thing here. This error should move to useDefineForClassFields: false at the same time as the other errors from #33401 and #33423.
@sandersn yeah, you fixed that a while back in #34987
... and in that PR we already talked about the order of parameter properties vs. class field initializers.
TypeScript Version: 3.8.0-dev.20200123
Search Terms: useDefineForClassFields parameter
Code
Expected behavior:
Transpiled code works (
bar
is defined in the constructor as it's done for the downlevel emit) OR used-before-assignment error onthis.foo
in the initializer ofbar
.Actual behavior:
Since the initializer of
bar
is run before the assignment offoo
, there's a runtime error.This code used to work for ages (of course without native class fields). A lot of code that uses dependency injection looks like this.
Playground Link: https://www.typescriptlang.org/play/?useDefineForClassFields=true&target=99&ts=3.8.0-dev.20200123&ssl=4&ssc=2&pln=1&pc=1#code/MYGwhgzhAEDC0G8BQ1oCMwCdoF5oBcALASwgDoAzAeyrI0wG4VpgqA7CfTAV2HyswAKAA6ZiANzD4AptGpUAXInpLOYtgHMAvgEpEWpFqA
Related Issues:
I thought this was already discussed somewhere with @RyanCavanaugh and @sandersn, but I couldn't find an issue for that.
Found while looking at #36405. That PR would need an exception if parameter properties are involved IF you want to continue supporting the example code.
The text was updated successfully, but these errors were encountered: