Issue
When I declare variables sometimes I link back to an Angular service.
Typescript throws this error: "Property 'houseService' is used before its initialization."
@Component({
selector: 'app-map-overview',
templateUrl: './map-overview.component.html',
styleUrls: ['./map-overview.component.sass'],
})
export class MapOverviewComponent implements AfterViewInit {
house$ = this.houseService.house$
constructor(
public houseService: HouseService,
) {
It worked before with es2020 and angular 14.
Now I moved over to es2022 and angular 16.
If I have the constructor before the properties it is fine, but that is a lot of code change and against some best (readability) practices.
Is there somehow I can suppress this error on tsconfig.json
level?
Edit: Might have a wrong typscript version loaded in VS. After restart, these errors disappeared
Solution
A new project shows that it works and I fixed it now in my migration. I think its a combi of:
- move up to
es2022
- typescript
4.8
to5.1
useDefineForClassFields: false,
(was not there before intsconfig.json
)
Thanks @Cuzy for pointing in the right direction.
On a new project you can remove (not false) useDefineForClassFields
and you end up with the same error
Answered By - GeoDev
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.