After following a tutorial, I created a class and noticed that the interface
was declared with an as
name. I'm wondering if this is necessary. What is the purpose of reassigning it when it was already assigned?
My TypeScript code:
import { Component, OnInit } from '@angular/core'
import { ICurrentWeather } from '../interfaces'
@Component({
selector: 'app-current-weather',
templateUrl: './current-weather.component.html',
styleUrls: ['./current-weather.component.css']
})
export class CurrentWeatherComponent implements OnInit {
current: ICurrentWeather /*already assigned*/
constructor() {
this.current = {
city: 'Bethesda',
country: 'US',
date: new Date(),
image: 'assets/img/sunny.png',
temperature: 72,
description: 'sunny',
} as ICurrentWeather /*is it required again?*/
}
ngOnInit() {}
}
Definition for Icon Weather:
export interface ICurrentWeather {
city: string
country: string
date: Date
image: string
temperature: number
description: string
}