I have this code:
interface Heroe {
title:string,
hero:string,
ranking:number,
}
export class AppComponent {
heroe : Heroe = {
title : 'Tour of Heroes',
hero : 'Windstorm',
ranking :1
}
}
if I replace Class instead Interface code works:
class Heroe {
title:string,
hero:string,
ranking:number,
}
export class AppComponent {
heroe : Heroe = {
title : 'Tour of Heroes',
hero : 'Windstorm',
ranking :1
}
}
It's correct to use class like interfaces, when class have no methods, just type of variables, that is not a problem?. In angular demo use this way, have a class and not interface:
https://angular.io/docs/ts/latest/tutorial/toh-pt1.html
in this last case I have a class instead Interface, and have no interface for the class,
the correct would not be have Interface first, then a Class based in the interface ? , but if both have the same name; how typescript which must use ??
Example:
interface Heroe {
title:string,
hero:string,
ranking:number,
}
class Heroe interface Heroe {
title:string,
hero:string,
ranking:number,
}
export class AppComponent {
heroe : Heroe = {
title : 'Tour of Heroes',
hero : 'Windstorm',
ranking :1
}
}
I's ok too have Heroe same name class like interface?