์ „์ฒด ๊ธ€

์ „์ฒด ๊ธ€

    ์“ฐ๋ ˆ๋“œ ์ƒ์„ฑ, ์“ฐ๋ ˆ๋“œํ’€๋ง, Task ๋ช…์‹œ

    using System; using System.Threading; using System.Collections.Generic; namespace ServerCore { class Program { static void MainThread() { Console.WriteLine("hello Thread!"); } static void Main(string[] args) { Thread t = new Thread(MainThread); t.Start(); //๋ณ„๋„์˜ ์“ฐ๋ ˆ๋“œ๊ฐ€ ์‹คํ–‰๋จ Console.WriteLine("Hello World!"); } } } ๋ฐฑ๊ทธ๋ผ์šด๋“œ ์“ฐ๋ ˆ๋“œ using System; using System.Threading; using System.Collections.Generic; name..

    Union๊ณผ ๋˜ ๋‹ค๋ฅธ Intersection ํƒ€์ž…

    Union๊ณผ ๋˜ ๋‹ค๋ฅธ Intersection ํƒ€์ž…

    Union์ด Or์ด๋ผ๋ฉด Intersection์€ And & ์ผ ๊ฒƒ์ด๋‹ค^^ type Student = { name: string; score: number; }; type Worker = { employeeId: number; work: () => void; }; function internWork(person: Student & Worker) { console.log(person.name, person.employeeId, person.work()); } internWork({ name: "ํ™๊ธธ๋™", score: 86, employeeId: 6, work: ()=> {}, }); //ํ™๊ธธ๋™ 6 undefined ์œ„์˜ ์ฝ”๋“œ๊ฐ€ ์•„๋ž˜์™€ ๊ฐ™๋‹ค๋ฉด, type Student = { name: string; score..

    ํ•„์ˆ˜ ํƒ€์ž…! Discriminated Union

    ์ฐจ๋ณ„ํ™”(๊ตฌ๋ถ„) ํ•  ์ˆ˜ ์žˆ๋Š” Union ์•„๋ž˜ ์ฝ”๋“œ๋ฅผ ๊ฐœ์„ ํ•ด๋ณด์ž type SuccessState = { response: { body: string; }; }; type FailState = { reason: string; }; type LoginState = SuccessState | FailState; function login(): SuccessState | FailState { return { response: { body: "logged in!", }, }; } function printLoginState(state: LoginState) { if ("response" in state) { console.log(`๐ŸŽ‰ ${state.response.body}`); } else { console.log..

    ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ 1์žฅ ์—ฐ์Šต๋ฌธ์ œ | ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ์˜ ์ถ”๋ก 

    1. ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ์˜ ์ถ”๋ก  ๋ฐฉ์‹ ์•Œ๊ธฐ let a = 10423; //number let b = "apple"; //string const c = "grape"; //"grape" let d = [true, false, true]; //boolean[] let e = { ์ด๋ฆ„: "smith" }; //{ ์ด๋ฆ„: string } let f = [1, false, "ํ™๊ธธ๋™"]; //(number | boolean | string)[] const g = [3]; //number[] let h = null; //any 2. ์—๋Ÿฌ์˜ ์›์ธ ํŒŒ์•…ํ•˜๊ธฐ a. let i: 3 = 3; i = 4; ~ //'4'ํ˜•์‹์€ '3'ํ˜•์‹์— ํ• ๋‹นํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค. ์›์ธ : i ๋ณ€์ˆ˜๋ฅผ ๋ช…์‹œ์ ์œผ๋กœ ์˜ค์ง ํ•˜๋‚˜์˜ ๊ฐ’์„ ๋‚˜ํƒ€๋‚ด๋Š” ํƒ€์ž…์ธ 'ํƒ€์ž…๋ฆฌํ„ฐ๋Ÿด..

    ์ง„์ •ํ•œ ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ์˜ ์‹œ์ž‘, Union ํƒ€์ž…

    ์ง„์ •ํ•œ ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ์˜ ์‹œ์ž‘, Union ํƒ€์ž…

    ์œ ๋‹ˆ์˜จ ํƒ€์ž…์€ ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ์—์„œ ์ฝ”๋”ฉํ•  ๋•Œ ๊ต‰์žฅํžˆ ๋งŽ์ด ์“ฐ๊ฒŒ ๋  ๊ฒƒ์ด๋‹ค. OR ๋˜๋Š” ํ•ฉ์ง‘ํ•ฉ์œผ๋กœ ์ดํ•ดํ•˜๋ฉด ์ถฉ๋ถ„ํ•  ๊ฒƒ์ด๋‹ค. type Direction = "left" | "right" | "up" | "down"; function move(direction: Direction) { console.log(direction); } type TileSize = 8 | 16 | 32; const tileA: TileSize = 16; //const tileB: TileSize = 10; //10 ํ˜•์‹์€ TileSize ํ˜•์‹์— ํ• ๋‹นํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค. //function : login -> success, fail type SuccessState = { response: { body: string; }; }; type F..

    ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ๋ฅผ ์“ฐ๋Š” ์ด์œ , type alias์™€ String Literal Types

    type alias(๋‚ด๊ฐ€ ์ƒˆ๋กœ์šด ํƒ€์ž…์„ ์ •์˜ํ•  ์ˆ˜ ์žˆ๋‹ค)๋ฅผ ์ด์šฉํ•˜๋ฉด ๊ธฐ๋ณธ์ ์ธ ํƒ€์ž…๋ถ€ํ„ฐ ๋ณต์žกํ•˜๊ณ  ์ •๊ตํ•œ ํƒ€์ž…๊นŒ์ง€ ์ •์˜ํ•  ์ˆ˜ ์žˆ๋‹ค. ๊ฐ€๋ น type Text = string; ์œ„์™€ ๊ฐ™์ด ์ž‘์„ฑํ•˜๋ฉด Text๋ผ๋Š” ์ƒˆ๋กœ์šด ํƒ€์ž…์€ ๋ฌธ์ž์—ด์„ ๋งํ•œ๋‹ค๊ณ  ์ง€์ •ํ•ด์ฃผ๋Š” ๊ฒƒ์ด๋‹ค. type Text = string; const name: string = "ํ™๊ธธ๋™"; const nickName: Text = "ํ™ฉ์ง„์ด"; console.log(name); //ํ™๊ธธ๋™ console.log(nickName); //ํ™ฉ์ง„์ด type alias ๋ฅผ ํ†ตํ•ด์„œ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ํŠน์ • ํ”„๋กœํผํ‹ฐ๊ฐ€ ๊ฐ•์ œ๋œ ๊ฐ์ฒด ํƒ€์ž…์„ ๋งŒ๋“ค ์ˆ˜๋„ ์žˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ๋ณ€์ˆ˜์˜ ํƒ€์ž…์„ type alias๋กœ ์ž‘์„ฑํ•œ ๊ฒƒ์œผ๋กœ ์ง€์ •ํ•ด์ฃผ๋ฉด ํŠน์ • ํ”„๋กœํผํ‹ฐ๋งŒ ํ• ๋‹นํ•  ์ˆ˜ ์žˆ์„ ๋ฟ๋”๋Ÿฌ ํŠน์ • ํ”„๋กœํผํ‹ฐ์˜ ํƒ€..

    ์Šคํ”„๋ ˆ๋“œ ์—ฐ์‚ฐ์ž, ๋ฐฐ์—ด, ํŠœํ”Œ

    ์Šคํ”„๋ ˆ๋“œ ์—ฐ์‚ฐ์ž์™€ ํ•จ๊ป˜ ์“ฐ๋Š” ๊ฒฝ์šฐ function addNum(...numbers: number[]): number { return numbers.reduce((a, b) => a + b); } console.log(addNum(1, 2)); console.log(addNum(1, 2, 3)); console.log(addNum(1, 2, 3, 4)); 3 6 10 ๋ฐฐ์—ด๊ณผ ํŠœํ”Œ nst fruits: string[] = ["์‚ฌ๊ณผ", "๋ฐ”๋‚˜๋‚˜"]; const numbers: Array = [1, 2, 3, 4, 5]; const cloths: [string, number] = ['์ฒญ๋ฐ”์ง€', 2]; console.log(cloths[0]); //์ฒญ๋ฐ”์ง€ ํŠœํ”Œ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์€ ๊ถŒ์žฅํ•˜์ง€ ์•Š๋Š”๋‹ค. const cloth..