Home > database >  Property 'values' does not exist on type 'unknown'. ionic/capacitor
Property 'values' does not exist on type 'unknown'. ionic/capacitor

Time:08-03

so i have been following this tutorial enter image description here

enter image description here

CodePudding user response:

It's an error from typescript. By default in angular tsconfig.json it has a configuration noImplicityAny. That means, you have to specify types, otherwise typescript will yell at you

Quick Fix (not-recommendable)

this.databaseService.getProductList().subscribe((res: any) => {
   this.products = res.values;
});

Recommended Fix

Service

interface Product {
   ...
}

interface ProductResponse {
   values: Product[];
}

getProductList() {
   return this.http.get<ProductResponse>('https://url/to/api');
}

// HomePage

products: Product[] = [];

this.databaseService.getProductList().subscribe((res) => {
   this.products = res.values;
});
  • Related