타입스크립트 핸드북으로 각자 공부한 뒤(함수, 리터럴 타입, 유니언과 교차 타입), 느낀 점을 공유
TS Playground - An online editor for exploring TypeScript and JavaScript
interface Fish {
swim(): void;
layEggs(): void;
}
interface Bird {
fly(): void;
layEggs(): void;
}
const fish: Fish = {
swim() {
console.log('swim');
},
layEggs() {
console.log('layEggs');
}
};
const bird: Bird = {
fly() {
console.log('fly');
},
layEggs() {
console.log('layEggs');
}
};
function getPet(): Fish | Bird {
return [fish, bird][Math.random()*2];
}
const pet = getPet();
pet.layEggs(); // 공통 속성이기 때문에 바로 사용가능
(pet as Bird).fly(); // 캐스팅을 해야 사용가능
(pet as Fish).swim(); // 어디에서 오류가 발생할지 모른다 -> BAD
interface Window {
title: string;
}
interface Window {
ts: import("typescript");
}
이런 식으로 선언하면 컴파일 시점에 합쳐져 Window가 title과 ts속성을 모두 가지게 된다.)
ROOT
IAM 사용자(IAM / S3(Object Storage) / EC2(Server) / VPC)
Identification and Access Management