Currently, I am delving into the world of Angular 8 as a beginner with this framework.
In my attempt to design a new user interface with additional elements, I encountered an unexpected linting error after smoothly adding the first two fields. The error message reads:
ERROR in src/app/weatherObject/weather-class.ts(27,17): error TS2345: Argument of type '{ cityName: any; degrees: number; impaction: number; }' is not assignable to parameter of type 'WeatherFeature'. Object literal may only specify known properties, and 'impaction' does not exist in type 'WeatherFeature'.
This is the Weather Feature interface being used:
interface WeatherFeature {
cityName: string,
degrees: number,
impaction: number //FIELD REJECTED
// sky: string //READY TO BE INSERTED, But due to impaction issue, it's on hold!
}
Below is the code snippet from the class where values are assigned:
import { Injectable } from '@angular/core';
import { BehaviorSubject } from 'rxjs';
import { WeatherForecastApiService } from '../weatherForecastApiService/weather-forecast-api.service';
@Injectable({
providedIn: 'root',
})
export class WeatherClass {
public weatherFeature = new BehaviorSubject<WeatherFeature>(undefined);
constructor(
private wfas: WeatherForecastApiService,
) {
this.retriver();
}
private retriver() {
this.wfas.getItalyWeatherData('Pisa').subscribe((response) => {
const ks: string[] = ['name', 'main', 'temp', 'pressure', 'weather'];
console.log(response[ks[1]][ks[3]], response[ks[4]][0][ks[1]]);
this.weatherFeature.next({
cityName: response[ks[0]],
degrees: Number((response[ks[1]][ks[2]] - 273.15).toFixed()),
impaction: Number(response[ks[1]][ks[3]]) //QUERY REGARDING INSERTION
});
});
}
}
The puzzling aspect for me is that despite expanding the interface, I continue to face the same error while trying to add new fields in the class file.
Hopefully, it's just a simple oversight or misunderstanding on my part.