Reputation: 913
While creating a web app, I stumbled upon an unusual error in my IDE (VSCode) while working on one of the services:
Error, property adapter does not exist in DetailDataService
In most cases, this error is fairly straight forward, whatever I'm trying to add isn't declared, so I should declare the missing variable or whatever. However, in this case, the variable in consideration was already declared in the constructor.
constructor(
adapter: SuiteAdapterService,
toastr: ToastrService,
translate: TranslatePipe
) {}
But whenever I gave reference to these in my functions (for example):
extractData(
module: string,
where_relate_field: string,
where_field_value: string
): any {
let params = this.initializeParams(
module,
where_relate_field,
where_field_value
);
this.adapter.post("listRecords", params).subscribe(
(response) => {
this.records = response.records;
},
(error) => {
let errmsg = this.translate.transform(
"pages[login_page][responses][error][" + error.text + "]"
);
this.toastr.error(errmsg);
}
);
}
The IDE shows me an error for all three (adapter, toastr, translate) that they do not exist. I found this strange because I have been doing the same for the rest of the services and they seem to be working perfectly fine. I thought there was an IDE issue so I changed to Atom but the error persisted. I ran ng s
to see if it was just an IDE problem, but turns out the error is somehow legit as it throws me the following:
ERROR in src/app/services/dynamic-loading/data/detail/detail-data.service.ts(70,10): error TS2339: Property 'adapter' does not exist on type 'DetailDataService'.
src/app/services/dynamic-loading/data/detail/detail-data.service.ts(75,27): error TS2339: Property 'translate' does not exist on type 'DetailDataService'.
src/app/services/dynamic-loading/data/detail/detail-data.service.ts(78,14): error TS2339: Property 'toastr' does not exist on type 'DetailDataService'.
What am I doing wrong here?
Upvotes: 2
Views: 1135
Reputation: 913
I feel stupid. I forgot to declare the scope of the declarations in the constructor. It should have been:
constructor(
private adapter: SuiteAdapterService,
private toastr: ToastrService,
private translate: TranslatePipe
) {}
I find this confusing for a language that is not strictly typed to have constructor declarations that should have their scope defined. Perhaps that is a discussion for another day.
Upvotes: 2