๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

TypeScript4

Typescript - Interfaces (Typescript์—์„œ Object์˜ ๋ชจ์–‘์„ ์•Œ๋ ค์ฃผ๋Š” ๋ฐฉ๋ฒ• / ์ƒ์†๋ฐ›๊ธฐ_extends) โœ… Typescript์—์„œ Object์˜ ๋ชจ์–‘์„ ์•Œ๋ ค์ฃผ๋Š” ๋ฐฉ๋ฒ• : type ํ‚ค์›Œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์˜ค๋ธŒ์ ํŠธ์˜ ๋ชจ์–‘์„ ์•Œ๋ ค์ฃผ๋Š” ๋ฐฉ๋ฒ• : interface ํ‚ค์›Œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์˜ค๋ธŒ์ ํŠธ์˜ ๋ชจ์–‘์„ ์•Œ๋ ค์ฃผ๋Š” ๋ฐฉ๋ฒ• ๊ณตํ†ต์  ์ฐจ์ด์  Type ์˜ค๋ธŒ์ ํŠธ์˜ ๋ชจ์–‘์„ ๊ฒฐ์ •ํ•˜๋Š” ์—ญํ• ์ด๋‹ค. type ํ‚ค์›Œ๋“œ๋Š” interface ํ‚ค์›Œ๋“œ์— ๋น„ํ•ด ์ข€ ๋” ํ™œ์šฉํ•  ์ˆ˜ ์žˆ๋Š”๊ฒŒ ๋งŽ๋‹ค. Interface interface๋Š” ์˜ค๋ธŒ์ ํŠธ์˜ ๋ชจ์–‘์„ ํŠน์ •ํ•œ๋‹ค๋Š” ์˜ค์ง ํ•œ๊ฐ€์ง€ ์šฉ๋„๋งŒ ๊ฐ€์ง€๊ณ  ์žˆ๋‹ค. : Type type Team = 'red'| 'blue' |'yellow' type Health = 1 | 5 | 10 type Player = { nickname: string, team: Team, hea.. 2022. 12. 23.
Typescript - Function(Generic) ๋ฐฐ์—ด์„ ๋ฐ›๊ณ , ๊ทธ ๋ฐฐ์—ด์˜ ์š”์†Œ๋ฅผ printํ•ด์ฃผ๋Š” ํ•จ์ˆ˜ ๋งŒ๋“ค๊ธฐ call signatures๋ฅผ ๋งŒ๋“ค๊ณ  ์‚ฌ์šฉ๋  concrete type์œผ๋กœ ์ž‘์„ฑํ•˜๊ธฐ! type SuperPrint ={ (arr: number[]): void, (arr: boolean[]): void, (arr: string[]): void, (arr: (number|boolean)[]): void, } const superPrint: SuperPrint = (arr) => { arr.forEach(i => console.log(i)) } superPrint([1, 2, 3, 4]) superPrint([true, false, true]) superPrint(['a', 'b', 'c']) superPrint([1, 2, true, false]).. 2022. 12. 22.
Typescript - Function(call signatures, Overloading) Call signatures // call signatures ์ด๋ž€? // ex.(a:number, b:number) => number // ์ธ์ž์˜ ํƒ€์ž…์ด๋ž‘ ํ•จ์ˆ˜์˜ ๋ฐ˜ํ™˜ ํƒ€์ž…์„ ์•Œ๋ ค์คŒ. // call signatures๋ฅผ ์„ ์–ธํ•˜๋Š” ๋ฐฉ๋ฒ• 1) type Add = (a:number, b: number) => number; const add : Add = (a, b) => a + b // call signatures๋ฅผ ์„ ์–ธํ•˜๋Š” ๋ฐฉ๋ฒ• 2) type Add = { (a:number, b: number) : number } const add : Add = (a, b) => a + b // ์ž˜๋ชป ์‚ฌ์šฉ๋œ ์˜ˆ const add : Add = (a, b) => {a + b} // Error: Type 'void' is n.. 2022. 12. 22.
Typescript - readonly, Tuple, any, unknown, void, never readonly // readonly๋Š” ์š”์†Œ๋“ค์„ ์ฝ๊ธฐ์ „์šฉ์œผ๋กœ ๋งŒ๋“ฌ. const numbers : readonly number[] =[1,2,3,4,5] numbers.push(1) // ์ž‘๋™ํ•˜์ง€ ์•Š๋Š”๋‹ค. const array : number[] = [1,2,3,4,5] array.push(1) // ์ž‘๋™์ด ๋œ๋‹ค. Tuple // ์ •ํ•ด์ง„ ๊ฐœ์ˆ˜์™€ ์ˆœ์„œ์— ๋”ฐ๋ผ ๋ฐฐ์—ด ์„ ์–ธ const user: [string, number, boolean] = ["aaa", 1, true] any // ๋ฌด์—‡์ด๋“  ์ž…๋ ฅํ•  ์ˆ˜ ์žˆ๊ฒŒ๋œ๋‹ค. // ํƒ€์ž…์ฒดํฌ๋ฅผ '๋น„ํ™œ์„ฑํ™”' ์‹œ์ผœ๋ฒ„๋ฆฐ๋‹ค. const a : any[] = [1,2,3,4] const b : any = true a + b // ์˜ค๋ฅ˜๊ฐ€ ๋‚˜์ง€ ์•Š์Œ. // any์˜ ์‚ฌ์šฉ์€ ์ข‹์ง€์•Š์œผ๋ฉฐ, .. 2022. 12. 22.