Type alias vs interface
type EatType = (food: string) => void;
interface IEat {
(food: string): void;
}
type PersonLit = string[];
interface IPersonList{
[index: number]: string;
}
interface ErrorHandling{
success: boolean;
error?: {message: string};
}
interface ArtistsData{
artists: {name: string}[];
}
type ArtistsResponseType = ArtistsData & ErrorHandling;
interface IArtistsResponse extends ArtistsData, ErrorHandling{}
let art: ArtistsResponseType;
let iar: IArtistsResponse;
interface Bird{
fly(): void;
layEggs(): void;
}
interface Fish{
swim(): void;
layEggs(): void;
}
type PetType = Bird | Fish;
interface IPet extends PetType{}
class Pet implements PetType{}
- Declaration Merging: interface에서 같은 이름으로 다른 곳에서 속성을 정의하면 사용할 때에는 자동으로 해당 속성이 합쳐지는 꼴이 됨 (alias는 불가능)