์ ์ฒด ๊ธ
[ํ์ ์คํฌ๋ฆฝํธ] ํ์ ๋ณ์นญ ์ธํฐ์น์ ์ ์ํ ํ์ฅ
์์ ๊ฐ์ด ์ธ๊ฐ์ ํ์ ๋ณ์นญ์ ๋์๋ค. ์ด๋ฅผ ํ ๋๋ก ์ฌ๋ฌ๊ฐ์ง ์คํ์ ํด๋ณผ ๊ฒ์ด๋ค. ํ์ ๋ณ์นญ์ extends๋ผ๋ ๋ช ๋ น์ด๊ฐ ์๊ณ ์ธํฐ์น์ (&)๋ฅผ ์ด์ฉํด ํ์ฅํ๋ค. type TreeNode = { value: string; }; type LeafNode = TreeNode & { isLeaf: true; }; type InnerNode = TreeNode & { children: [TreeNode] | [TreeNode, TreeNode]; }; 1. let a: TreeNode = { value: "a" }; //ํต๊ณผ let a1: TreeNode = { value: "a" , isLeaf: true}; ~~~~~~~~~~~~~ 2. let b: LeafNode = { value: "b", isLeaf: t..
[ํ์ ์คํฌ๋ฆฝํธ] ์ ๋ค๋ฆญ ํ์ ๋ณ์นญ
์๋ ์คํ์ผ๋ค๋ ์ ๋ค๋ฆญ ํ์ ๋ณ์นญ์ด๋ค. //์ฝ๊ธฐ ์ ์ฉ ๋ฐฐ์ด๊ณผ ํํ ๋ง๋๋ ์ฌ๋ฌ๊ฐ์ง ์ ์ธ ๋ฐฉ๋ฒ type A = readonly string[]; //readonly string[] type B = ReadonlyArray;//readonly string[] type C = Readonly; //readonly string[] type D = readonly [number,string]; //readonly [number,string] type E = Readonly;//readonly [number,string] ๊ฐ๋จํ ์๋ฅผ ํตํด ํ์ ๋ณ์นญ์์ ์ ๋ค๋ฆญ์ ํ์ฉํ๋ ๋ฐฉ๋ฒ์ ๋ ์์ธํ ์ดํด๋ณด์. (์ฐธ๊ณ ๋ก ์ด ์์ ์ ์ ts์์ DOM์ ๋ถ๋ฅด๊ธฐ ์ํด tsconfig.json์ lib ์ต์ ํ์ ์คํฌ๋ฆฝํธ๊ฐ ๋น๋ ๋ ..
[ํ์ ์คํฌ๋ฆฝํธ] ์ ๋ค๋ฆญ ํ์ ๋ช ์ ์ฃผ์์ฌํญ
1. ์ ๋ค๋ฆญ ํ์ ๋ช ์ ์ฃผ์์ฌํญ ์ ๋ค๋ฆญ์ ํ์ ์ ๋ช ์ํ ๋๋ ๋ชจ๋ ํ์ํ ์ ๋ค๋ฆญ ํ์ ์ ๋ช ์ํ๊ฑฐ๋ ๋ฐ๋๋ก ์๋ฌด ๊ฒ๋ ๋ช ์ํด์๋ ์ ๋๋ค. ์ฆ, ์ด๋ ๊ฒ ์ฐ๊ฑฐ๋ ( ํ์ ๋ช ์) function map(array: T[], f: (item: T) => U): U[] { let result = []; for (let i = 0; i _ === "a")); //[ false, false, true ] ์ด๋ ๊ฒ ์จ์ผ ํ๋ค. (ํ์ ์ถ๋ก ) function map(array: T[], f: (item: T) => U): U..
[ํ์ ์คํฌ๋ฆฝํธ ๊ณตํ] User-Defined Type Guards
TypeScript: Documentation - Advanced Types (typescriptlang.org) Documentation - Advanced Types Advanced concepts around types in TypeScript www.typescriptlang.org User-Defined Type Guards It would be much better if once we performed the check, we could know the type of pet within each branch. It just so happens that TypeScript has something called a type guard. A type guard is some expression th..
[์๋ฐ์ ์ ์] Hello Java & Eclipse ๋จ์ถํค
์๋ก์ด ํด๋์ค๋ฅผ ๋ง๋๋ ค๋ฉด CTRL + n ํด๋์ค๋ช ์ฐพ๊ธฐ ctrl + SHIFT + R main ์ ์น๊ณ CTRL + SPACE : ๋ฉ์ธ ๋ฉ์๋ ์๋ ์์ฑ sysout์ ์น๊ณ CTRL + SPACE ์ ๋๋ฅด๋ฉด {System.out.printIn()}์ผ๋ก ์๋ ํ์ฅ https://youtu.be/E8fTLFuc7X4 CMD์ฐฝ์์ C:\jdk11\work>javac Helllo.java C:\jdk11\work>java Hello Hello, World https://youtu.be/emllFzqD1-0 ์ดํด๋ฆฝ์ค๋ ๊ธฐ๋ณธ์ ๊ทธ์ฌ ์์ค ํ์ผ๊ณผ ํด๋์ค ํ์ผ์ ๋ณ๋์ ํด๋์ ๋ด์์ ๊ด๋ฆฌํ๋ค. ํนํ .์ผ๋ก ์์ํ๋ ํ์ผ๋ค์ ์ดํด๋ฆฝ์ค๊ฐ ์๋์ผ๋ก ์์ฑํด์ ๋ง๋ ๊ด๋ จ ํ์ผ๋ค์ด๋ฏ๋ก ๊ฑด๋ค์ง ์๋ ๊ฒ์ด ์ข๋ค.
[ํ์ ์คํฌ๋ฆฝํธ] ์ ๋ค๋ฆญ ํด๋์ค
//๋ค๋ฅธ ํ์ ์ผ๋ก ์ธ ์ ์๊ฒ ๋ฐ๊พธ๊ธฐ //either: a or b interface Either { left: () => T; right: () => U; } class SimpleEither implements Either { constructor(private leftValue: T, private rightValue: U) {} left(): T { return this.leftValue; } right(): U { return this.rightValue; } } const either = new SimpleEither(4, { name: "ํ๊ธธ๋", age: 18 }); console.log(either.left()); //4 console.log(either.right()); //ํ๊ธธ๋โ /..