May 2018
Intermediate to advanced
512 pages
11h 3m
English
So far, we have been passing parameters to get the weather for a city using its name and country code. By allowing users to enter zip codes, we must make our service more flexible to accept both types of inputs.
OpenWeatherMap's API accepts URI parameters, so we can refactor the existing getCurrentWeather function using a TypeScript union type and using a type guard, we can supply different parameters, while preserving type checking:
app/src/weather/weather.service.ts getCurrentWeather( search: string | number, country?: string ): Observable<ICurrentWeather> { let uriParams = '' if (typeof search === 'string') ...Read now
Unlock full access