简体   繁体   English

Angular(6) 的错误 TS2304:找不到名称“ICurrentWeatherData”

[英]Angular(6)'s Error TS2304: Cannot find name 'ICurrentWeatherData'

When working with Angular6 the Error happens, though my app can be running and working properly, the tests will not pass.使用 Angular6 时发生错误,尽管我的应用程序可以运行并正常工作,但测试不会通过。 Here's the code snippet of the file:这是文件的代码片段:

`import { Injectable } from '@angular/core'
import { HttpClient } from '@angular/common/http'
import { Observable } from 'rxjs'
import { map } from 'rxjs/operators'
import { environment } from '../../environments/environment'
import { ICurrentWeather } from '../interfaces'

@Injectable()
export class WeatherService {
  constructor(private httpClient: HttpClient) {}

  getCurrentWeather(city: string, country: string): Observable<ICurrentWeather> {
    return this.httpClient
      .get<ICurrentWeatherData>(
        `${environment.baseUrl}api.openweathermap.org/data/2.5/weather?` +
          `q=${city},${country}&appid=${environment.appId}`
      )
      .pipe(map(data => this.transformToICurrentWeather(data)))
  }

  private transformToICurrentWeather(data: ICurrentWeatherData): ICurrentWeather {
    return {
      city: data.name,
      country: data.sys.country,
      date: data.dt * 1000,
      image: `http://openweathermap.org/img/w/${data.weather[0].icon}.png`,
      temperature: this.convertKelvinToFahrenheit(data.main.temp),
      description: data.weather[0].description,
    }
  }
  private convertKelvinToFahrenheit(kelvin: number): number {
    return (kelvin * 9) / 5 - 459.67
  }
}`
  • ERROR in src/app/weather/weather.service.ts(14,12): error TS2304: Cannot find name 'ICurrentWeatherData'. src/app/weather/weather.service.ts(14,12) 中的错误:错误 TS2304:找不到名称“ICurrentWeatherData”。

  • src/app/weather/weather.service.ts(21,44): error TS2304: Cannot find name 'ICurrentWeatherData'. src/app/weather/weather.service.ts(21,44): 错误 TS2304: 找不到名称“ICurrentWeatherData”。

您没有导入 ICurrentWeatherData,在接口导入中我只看到 ICurrentWeather

u should import that interface i thinks to that's works when u replace this :当你替换这个时,你应该导入我认为有效的接口:

import { ICurrentWeather } from '../interfaces'

to :到 :

import { ICurrentWeather } from '../interfaces/ICurrentWeather'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM