TypeScript tips
function getToken() {
return localStorage.getItem("token");
}두가지 타입 이상이 추론되는 경우
promise, async-await
generic
Last updated
Was this helpful?
function getToken() {
return localStorage.getItem("token");
}Last updated
Was this helpful?
Was this helpful?
interface IMachine {
type: string;
}
class Car implements IMachine {
type: "CAR";
wheel: number;
}
class Boat implements IMachine {
type: "BOAT";
motor: number;
}
function getWhellOrMotor(machine: Car | Boat): number {
if (machine.type === "CAR") {
return machine.wheel;
} else {
return machine.motor;
}
}<string>token;
token as string; // 보통은 요고const a = token as string;
a.split("/"); // runtime error 발생 가능성const listeElement = document.querySelector('#list');
listElement.append(...)const res = await axios.get<{ email: string }>("https://api.marktube.tv/v1/me");