목록JAVASCRIPT/타입스크립트 (4)
Illie

1. 복습 type Nickname = string; type Health = number; type Friends = Array type Player = { nickname: string, healthBar: number } type Player2 = { nickname: Nickname, healthBar: Health } const nico:Player = { nickname: "nico", healthBar: 3 } type Food = string; const kimchi:Food = "delicious" 2. 정해진 값만 사용가능하게 type / interface 지정하기 type Team = "red" | "blue" | "yellow"; type Health = 1 | 5 | 10 type..

1. Class class Player { constructor( private firstName:string, private lastName:string, public nickName:string, ){} } const nico = new Player("nico", "las", "니코") // ERR(firstName은 private 이므로...) nico.firstName 2. Abstract class(추상클래스) - 다른 클래스가 상속받을 수 있는 클래스 - 직접 인스턴스 생성 불가능 abstract class User { constructor( private firstName:string, private lastName:string, public nickName:string, ){} } clas..

1. Call Signature // ERR -> a, b가 any타입이기 때문 function add(a, b){ return a + b; } // ALLOWED function add(a:number, b:number){ return a + b; } // ALLOWED const add = (a:number, b:number) => a+b // Call signatures type Add = (a:number, b:number) => number; const add:Add = (a,b) => a + b // Call signature 에러 조심 (중괄호) const add:Add = (a,b) => {a + b} // -> void 2. Overloading(오버로딩) 여러 개의 Call Signat..

0. 기본 type Age = number; type Name = string; type Player = { name: Name age?: Age } const playerMaker = (name: string): Player => ({name}) const nico = playerMaker("nico") nico.age = 12 // 항상 정해져있는 갯수의 요소를 가져오는 배열을 생성해야할 때 유용 const player: [string, number, boolean] = ["nico", 1, true]; player[0] = 1; // not allowed ([0]: string) const player: readonly [string, number, boolean] = ["nico", 1, true..