Ver3.0 ๐ ํ์ ์คํฌ๋ฆฝํธ ํธ๋ ๋ ๋ถ์๊ณผ ์ฐจ์ธ๋ ํ์ ์์คํ ๋ฐ์ ๋ฐฉํฅ

๐ ํ์ ์คํฌ๋ฆฝํธ ํธ๋ ๋ ๋ถ์๊ณผ ์ฐจ์ธ๋ ํ์ ์์คํ ๋ฐ์ ๋ฐฉํฅ
ํ์ฌ์ ๋ฏธ๋๋ฅผ ๊ดํตํ๋ ํ์ ์คํฌ๋ฆฝํธ์ ๋ชจ๋ ๊ฒ
๐ฏ ํ์ ์คํฌ๋ฆฝํธ, ์ ์ง๊ธ ์ด๋ ๊ฒ ํซํ๊ฐ?
์๋ ! ์ค๋์ ๊ฐ๋ฐ์๋ค ์ฌ์ด์์ ์์ฆ ๊ฐ์ฅ ๋จ๊ฑฐ์ด ์ธ์ด ์ค ํ๋์ธ ํ์ ์คํฌ๋ฆฝํธ์ ๋ํด ๊น์ด ์๊ฒ ํํค์ณ๋ณผ ๊ฑฐ์ผ. ์์งํ ๋งํ๋ฉด, 5๋ ์ ๋ง ํด๋ "ํ์ ์คํฌ๋ฆฝํธ? ๊ทธ๊ฑฐ ์ ์จ?" ๋ผ๋ ๋ฐ์์ด ๋ง์๋๋ฐ, ์ง๊ธ์ ์์ ํ ๋ถ์๊ธฐ๊ฐ ๋ฐ๋์์ด. ๐ฅ2024๋ ๊ธฐ์ค์ผ๋ก Stack Overflow ๊ฐ๋ฐ์ ์ค๋ฌธ์กฐ์ฌ์ ๋ฐ๋ฅด๋ฉด, ํ์ ์คํฌ๋ฆฝํธ๋ ๊ฐ์ฅ ์ฌ๋๋ฐ๋ ํ๋ก๊ทธ๋๋ฐ ์ธ์ด 5์ ์์ ๋ค์ด๊ฐ๊ณ , GitHub์์๋ ๊ฐ์ฅ ๋น ๋ฅด๊ฒ ์ฑ์ฅํ๋ ์ธ์ด ์ค ํ๋๋ก ๊ผฝํ๊ณ ์์ด. ํนํ ํ๋ก ํธ์๋ ๊ฐ๋ฐ ๋ถ์ผ์์๋ ๊ฑฐ์ ํ์ค์ฒ๋ผ ์๋ฆฌ ์ก์์ง.
๊ทธ๋ฐ๋ฐ ์ ์ด๋ ๊ฒ ์ธ๊ธฐ๊ฐ ๋ง์์ก์๊น? ๊ฐ๋จํด. ํ์ ์์ ์ฑ์ด๋ผ๋ ๊ฐ๋ ฅํ ๋ฌด๊ธฐ ๋๋ถ์ด์ผ. ์๋ฐ์คํฌ๋ฆฝํธ์ ์์ ๋ก์์ ์ ์งํ๋ฉด์๋, ๋๊ท๋ชจ ํ๋ก์ ํธ์์ ๋ฐ์ํ ์ ์๋ ๋ฒ๊ทธ๋ฅผ ์ฌ์ ์ ์ก์๋ผ ์ ์๊ฑฐ๋ . ๋ง์น ์์ ๋ฒจํธ๋ฅผ ๋งค๊ณ ์ด์ ํ๋ ๊ฒ๊ณผ ๊ฐ์ ๋๋์ด๋๊น? ๐ก๏ธ
๐ 2024๋ ํ์ ์คํฌ๋ฆฝํธ ํธ๋ ๋ ํํฉ
์, ์ด์ ๋ณธ๊ฒฉ์ ์ผ๋ก ํ์ฌ ํ์ ์คํฌ๋ฆฝํธ ์ํ๊ณ๊ฐ ์ด๋ป๊ฒ ๋์๊ฐ๊ณ ์๋์ง ์ดํด๋ณผ๊น? ์ต๊ทผ ๋ช ๋ ๊ฐ ์ ๋ง ๋ง์ ๋ณํ๊ฐ ์์์ด. ๐๐ ์ฃผ์ ์ฑํ ํํฉ
๋จผ์ ๋๋ผ์ด ํต๊ณ๋ถํฐ ๋ณด์. 2024๋ ํ์ฌ npm ๋ค์ด๋ก๋ ๊ธฐ์ค์ผ๋ก ํ์ ์คํฌ๋ฆฝํธ๋ ์ฃผ๊ฐ 5์ฒ๋ง ํ ์ด์ ๋ค์ด๋ก๋๋๊ณ ์์ด. ์ด๊ฒ ์ผ๋ง๋ ๋๋จํ ์์น๋๋ฉด, 5๋ ์ ๊ณผ ๋น๊ตํ์ ๋ ์ฝ 10๋ฐฐ ์ด์ ์ฆ๊ฐํ ๊ฑฐ์ผ. ๐ํนํ ์ฃผ๋ชฉํ ๋งํ ๊ฑด ๊ธฐ์ ๋ค์ ์ฑํ๋ฅ ์ด์ผ. ๊ตฌ๊ธ, ๋ง์ดํฌ๋ก์ํํธ, ์์ด๋น์ค๋น, ์ฌ๋, ์์ฌ๋ ๋ฑ ๊ธ๋ก๋ฒ ํ ํฌ ๊ธฐ์ ๋ค์ ๋ฌผ๋ก ์ด๊ณ , ๊ตญ๋ด ๋๊ธฐ์ ๋ค๋ ์๋คํฌ์ด ํ์ ์คํฌ๋ฆฝํธ๋ก ์ ํํ๊ณ ์์ด. ๋ค์ด๋ฒ, ์นด์นด์ค, ํ ์ค ๊ฐ์ ํ์ฌ๋ค๋ ์ ๊ท ํ๋ก์ ํธ๋ ๊ฑฐ์ ํ์ ์คํฌ๋ฆฝํธ๋ก ์์ํ๋ค๊ณ ๋ด๋ ๋ฌด๋ฐฉํด.
๐ผ ๊ธฐ์ ๋ณ ํ์ ์คํฌ๋ฆฝํธ ํ์ฉ ์ฌ๋ก
๐ต Microsoft (๋ง์ดํฌ๋ก์ํํธ)๋น์ฐํ๊ฒ๋ ํ์ ์คํฌ๋ฆฝํธ๋ฅผ ๋ง๋ ํ์ฌ๋ต๊ฒ, VS Code๋ฅผ ๋น๋กฏํ ๊ฑฐ์ ๋ชจ๋ ํ๋ก์ ํธ์์ ํ์ ์คํฌ๋ฆฝํธ๋ฅผ ์ฌ์ฉํ๊ณ ์์ด. VS Code ์์ฒด๊ฐ ํ์ ์คํฌ๋ฆฝํธ๋ก ์์ฑ๋์๊ณ , ์ด๋ ํ์ ์คํฌ๋ฆฝํธ์ ๊ฐ๋ ฅํจ์ ์ฆ๋ช ํ๋ ์ต๊ณ ์ ์ฌ๋ก์ง.
๐ด Google (๊ตฌ๊ธ)
๊ตฌ๊ธ์ ์๋ ์์ฒด ํ์ ์์คํ ์ธ Closure Compiler๋ฅผ ์ฌ์ฉํ์ง๋ง, ์ต๊ทผ์๋ Angular ํ๋ ์์ํฌ๋ฅผ ํ๋๋ก ํ์ ์คํฌ๋ฆฝํธ๋ก ๋๊ฑฐ ์ ํํ์ด. Angular 2+ ๋ฒ์ ๋ถํฐ๋ ํ์ ์คํฌ๋ฆฝํธ๊ฐ ๊ธฐ๋ณธ ์ธ์ด๊ฐ ๋์์ง.
๐ข Airbnb (์์ด๋น์ค๋น)
์์ด๋น์ค๋น๋ 2019๋ ์ ํ์ ์คํฌ๋ฆฝํธ ๋์ ํ 38%์ ๋ฒ๊ทธ๋ฅผ ์ฌ์ ์ ๋ฐฉ์งํ ์ ์์๋ค๊ณ ๊ณต์ ๋ฐํํ์ด. ์ด๊ฑด ์ ๋ง ์์ฒญ๋ ์์น์ผ. ๋ฒ๊ทธ ํ๋ ๊ณ ์น๋ ๋ฐ ๋๋ ์๊ฐ๊ณผ ๋น์ฉ์ ์๊ฐํ๋ฉด ๋ง์ด์ง.
๐ก Slack (์ฌ๋)
์ฌ๋์ ๋๊ท๋ชจ ์ฝ๋๋ฒ ์ด์ค๋ฅผ ์๋ฐ์คํฌ๋ฆฝํธ์์ ํ์ ์คํฌ๋ฆฝํธ๋ก ๋ง์ด๊ทธ๋ ์ด์ ํ๋ฉด์, ๊ฐ๋ฐ์ ์์ฐ์ฑ์ด ํฌ๊ฒ ํฅ์๋์๋ค๊ณ ๋ณด๊ณ ํ์ด. ํนํ ๋ฆฌํฉํ ๋ง ์์ ์ด ํจ์ฌ ์์ ํ๊ณ ๋นจ๋ผ์ก๋ค๊ณ ํด.
๐จ ํ๋ ์์ํฌ ์ํ๊ณ์ ๋ณํ
ํ์ ์คํฌ๋ฆฝํธ์ ์ํฅ๋ ฅ์ ํ๋ ์์ํฌ ์ํ๊ณ์์๋ ํ์ฐํ ๋๋ฌ๋. ์์ฆ ๋์ค๋ ๊ฑฐ์ ๋ชจ๋ ๋ชจ๋ ํ๋ ์์ํฌ๋ค์ด ํ์ ์คํฌ๋ฆฝํธ๋ฅผ 1๊ธ ์๋ฏผ(First-class citizen)์ผ๋ก ์ง์ํ๊ณ ์์ด. ๐ฏReact
๋ฆฌ์กํธ๋ ์๋ฐ์คํฌ๋ฆฝํธ๋ก ์์ฑ๋์์ง๋ง, ํ์ ์คํฌ๋ฆฝํธ ์ง์์ด ์ ๋ง ํ๋ฅญํด. Create React App์์๋ ํ์ ์คํฌ๋ฆฝํธ ํ ํ๋ฆฟ์ ๊ณต์ ์ง์ํ๊ณ , ์ต๊ทผ์๋ ๋ง์ ๊ฐ๋ฐ์๋ค์ด ์ฒ์๋ถํฐ ํ์ ์คํฌ๋ฆฝํธ๋ก ๋ฆฌ์กํธ ํ๋ก์ ํธ๋ฅผ ์์ํด.
@types/react ํจํค์ง์ ๋ค์ด๋ก๋ ์๋ง ๋ด๋ ์ ์ ์์ง.Vue.js
Vue 3๋ถํฐ๋ ํ์ ์คํฌ๋ฆฝํธ๋ก ์ฌ์์ฑ๋์์ด. Vue 2 ์์ ์๋ ํ์ ์คํฌ๋ฆฝํธ ์ง์์ด ์ข ์์ฌ์ ๋๋ฐ, Vue 3์์๋ ์์ ํ ๋ฌ๋ผ์ก์ง. Composition API์ ํ์ ์คํฌ๋ฆฝํธ์ ์กฐํฉ์ ์ ๋ง ํ์์ ์ด์ผ.
Angular
Angular๋ ์ฒ์๋ถํฐ ํ์ ์คํฌ๋ฆฝํธ๋ฅผ ๊ธฐ๋ณธ ์ธ์ด๋ก ์ฑํํ์ด. ์ฌ์ค์ ํ์ ์คํฌ๋ฆฝํธ ์์ด๋ Angular๋ฅผ ์ ๋๋ก ์ฌ์ฉํ ์ ์๋ค๊ณ ๋ด๋ ๋ผ. ์ด๊ฒ Angular์ ๊ฐ์ ์ด์ ์ง์ ์ฅ๋ฒฝ์ด๊ธฐ๋ ํ์ง.
Svelte
์ค๋ฒจํธ๋ ํ์ ์คํฌ๋ฆฝํธ ์ง์์ด ์ ๋ง ์ข์์ก์ด. SvelteKit์์๋ ํ์ ์คํฌ๋ฆฝํธ๋ฅผ ๊ธฐ๋ณธ์ผ๋ก ์ค์ ํ ์ ์๊ณ , ํ์ ์ฒดํน๋ ๋งค๋๋ฝ๊ฒ ์๋ํด.
Next.js & Remix
์๋ฒ ์ฌ์ด๋ ๋ ๋๋ง ํ๋ ์์ํฌ๋ค๋ ํ์ ์คํฌ๋ฆฝํธ๋ฅผ ์ ๊ทน ์ง์ํด. Next.js๋ ํ์ ์คํฌ๋ฆฝํธ ์ค์ ์ด ์ ๋ง ๊ฐ๋จํ๊ณ , Remix๋ ํ์ ์์ ์ฑ์ ์ค์ํ๊ฒ ์๊ฐํ๋ ํ๋ ์์ํฌ์ผ.
๐ฌ ํ์ ์คํฌ๋ฆฝํธ ํ์ ์์คํ ์ฌ์ธต ๋ถ์
์ด์ ํ์ ์คํฌ๋ฆฝํธ์ ํต์ฌ์ธ ํ์ ์์คํ ์ ๋ํด ๊น์ด ํ๊ณ ๋ค์ด๋ณผ๊น? ํ์ ์คํฌ๋ฆฝํธ์ ํ์ ์์คํ ์ ์ ๋ง ๊ฐ๋ ฅํ๊ณ ํํ๋ ฅ์ด ๋ฐ์ด๋. ๋จ์ํ "์ด ๋ณ์๋ ์ซ์์ผ, ์ ๋ณ์๋ ๋ฌธ์์ด์ด์ผ" ์์ค์ ํจ์ฌ ๋์ด์๊ฑฐ๋ . ๐งฌ๐ญ ๊ตฌ์กฐ์ ํ์ดํ (Structural Typing)
ํ์ ์คํฌ๋ฆฝํธ์ ๊ฐ์ฅ ์ค์ํ ํน์ง ์ค ํ๋๊ฐ ๋ฐ๋ก ๊ตฌ์กฐ์ ํ์ดํ์ด์ผ. ์ด๊ฒ ๋ญ๋๋ฉด, ํ์ ์ ์ด๋ฆ์ด ์๋๋ผ ๊ตฌ์กฐ(shape)๋ก ํ์ ์ ํ๋จํ๋ค๋ ๊ฑฐ์ง.์๋ฅผ ๋ค์ด๋ณผ๊ฒ:
interface Point {
x: number;
y: number;
}
interface Vector {
x: number;
y: number;
}
function printPoint(p: Point) {
console.log(`x: ${p.x}, y: ${p.y}`);
}
const vector: Vector = { x: 10, y: 20 };
printPoint(vector); // ๋ฌธ์ ์์ด ์๋!
Point์ Vector๋ ์์ ํ ๋ค๋ฅธ ํ์
์ด์ง๋ง, ๊ตฌ์กฐ๊ฐ ๊ฐ๊ธฐ ๋๋ฌธ์ ์๋ก ํธํ๋ผ. ์ด๊ฒ ๋ฐ๋ก ๊ตฌ์กฐ์ ํ์ดํ์ ๋ง๋ฒ์ด์ผ. ์๋ฐ๋ C# ๊ฐ์ ๋ช
๋ชฉ์ ํ์ดํ(Nominal Typing) ์ธ์ด์์๋ ์ด๊ฒ ๋ถ๊ฐ๋ฅํ์ง.์ด๋ฐ ํน์ฑ ๋๋ถ์ ํ์ ์คํฌ๋ฆฝํธ๋ ์๋ฐ์คํฌ๋ฆฝํธ์ ์ ์ฐ์ฑ์ ํด์น์ง ์์ผ๋ฉด์๋ ํ์ ์์ ์ฑ์ ์ ๊ณตํ ์ ์์ด. ๋ ํ์ดํ(Duck Typing)์ ์ฒ ํ๊ณผ๋ ์ ๋ง์๋จ์ด์ง์ง. "์ค๋ฆฌ์ฒ๋ผ ๊ฑท๊ณ ์ค๋ฆฌ์ฒ๋ผ ๊ฝฅ๊ฝฅ๊ฑฐ๋ฆฌ๋ฉด, ๊ทธ๊ฑด ์ค๋ฆฌ๋ค!" ๐ฆ
๐ฎ ๊ณ ๊ธ ํ์ ๊ธฐ๋ฅ๋ค
ํ์ ์คํฌ๋ฆฝํธ์ ํ์ ์์คํ ์ ์ ๋ง ๊ฐ๋ ฅํ ๊ธฐ๋ฅ๋ค์ ์ ๊ณตํด. ํ๋์ฉ ์ดํด๋ณด์.1. Union Types (์ ๋์จ ํ์ )
์ฌ๋ฌ ํ์ ์ค ํ๋๊ฐ ๋ ์ ์๋ ๊ฐ์ ํํํ ๋ ์ฌ์ฉํด:
type Status = "pending" | "success" | "error";
function handleStatus(status: Status) {
switch (status) {
case "pending":
console.log("์ฒ๋ฆฌ ์ค...");
break;
case "success":
console.log("์ฑ๊ณต!");
break;
case "error":
console.log("์๋ฌ ๋ฐ์");
break;
}
}
"succes" ๊ฐ์ ์คํ๋ฅผ ์น๋ฉด ์ปดํ์ผ ํ์์ ๋ฐ๋ก ์ก์์ฃผ๊ฑฐ๋ . โจ2. Intersection Types (๊ต์ฐจ ํ์ )
์ฌ๋ฌ ํ์ ์ ํฉ์ณ์ ์๋ก์ด ํ์ ์ ๋ง๋ค ์ ์์ด:
interface Colorful {
color: string;
}
interface Circle {
radius: number;
}
type ColorfulCircle = Colorful & Circle;
const cc: ColorfulCircle = {
color: "red",
radius: 42
};
์ด๊ฑด ์ ๋ง ๊ฐ๋ ฅํ ๊ธฐ๋ฅ์ด์ผ. ํ์ ๋ ๋ฒจ์์ ์กฐ๊ฑด๋ฌธ์ ์ฌ์ฉํ ์ ์์ด:
type IsString<T> = T extends string ? true : false;
type A = IsString<string>; // true
type B = IsString<number>; // false
// ์ค์ฉ์ ์ธ ์์
type Flatten<T> = T extends Array<infer U> ? U : T;
type Str = Flatten<string[]>; // string
type Num = Flatten<number>; // number
4. Mapped Types (๋งคํ๋ ํ์ )
๊ธฐ์กด ํ์ ์ ๋ณํํด์ ์๋ก์ด ํ์ ์ ๋ง๋ค ์ ์์ด:
type Readonly<T> = {
readonly [P in keyof T]: T[P];
};
type Partial<T> = {
[P in keyof T]?: T[P];
};
interface User {
name: string;
age: number;
}
type ReadonlyUser = Readonly<User>;
// { readonly name: string; readonly age: number; }
type PartialUser = Partial<User>;
// { name?: string; age?: number; }
Readonly์ Partial์ ํ์
์คํฌ๋ฆฝํธ์ ๋ด์ฅ๋ ์ ํธ๋ฆฌํฐ ํ์
์ด์ผ. ์ด๋ฐ ์์ผ๋ก ํ์
์ ๋ณํํ๋ ํจํด์ ์ ๋ง ์ ์ฉํ๊ฒ ์ฐ์ฌ.5. Template Literal Types (ํ ํ๋ฆฟ ๋ฆฌํฐ๋ด ํ์ )
ํ์ ์คํฌ๋ฆฝํธ 4.1์์ ์ถ๊ฐ๋ ๊ธฐ๋ฅ์ธ๋ฐ, ๋ฌธ์์ด ๋ฆฌํฐ๋ด ํ์ ์ ์กฐํฉํ ์ ์์ด:
type Direction = "left" | "right" | "top" | "bottom";
type Alignment = "start" | "center" | "end";
type AlignedDirection = `${Direction}-${Alignment}`;
// "left-start" | "left-center" | "left-end" |
// "right-start" | "right-center" | ... (์ด 12๊ฐ)
๐งช ํ์ ์ถ๋ก ์ ๋ง๋ฒ
ํ์ ์คํฌ๋ฆฝํธ์ ๋ ๋ค๋ฅธ ๊ฐ์ ์ ํ์ ์ถ๋ก (Type Inference)์ด์ผ. ๋ชจ๋ ํ์ ์ ์ผ์ผ์ด ๋ช ์ํ์ง ์์๋ ํ์ ์คํฌ๋ฆฝํธ๊ฐ ์์์ ํ์ ์ ์ถ๋ก ํด์ค.๊ธฐ๋ณธ ํ์ ์ถ๋ก
๋ณ์๋ฅผ ์ ์ธํ ๋ ํ์ ์ ๋ช ์ํ์ง ์์๋ ์ด๊ธฐ๊ฐ์ผ๋ก๋ถํฐ ํ์ ์ ์ถ๋ก ํด:
let x = 3; // number๋ก ์ถ๋ก
let y = "hello"; // string์ผ๋ก ์ถ๋ก
let z = [1, 2, 3]; // number[]๋ก ์ถ๋ก
// ํจ์ ๋ฐํ ํ์
๋ ์ถ๋ก
function add(a: number, b: number) {
return a + b; // ๋ฐํ ํ์
์ด number๋ก ์ถ๋ก ๋จ
}
ํจ์์ ๋งค๊ฐ๋ณ์ ํ์ ๋ ๋ฌธ๋งฅ์ ๋ฐ๋ผ ์ถ๋ก ๋ผ:
const numbers = [1, 2, 3, 4, 5];
// num์ ํ์
์ด ์๋์ผ๋ก number๋ก ์ถ๋ก ๋จ
numbers.forEach(num => {
console.log(num.toFixed(2));
});
๐ ์ต์ ํ์ ์คํฌ๋ฆฝํธ ๋ฒ์ ๋ณ ์ฃผ์ ๊ธฐ๋ฅ
ํ์ ์คํฌ๋ฆฝํธ๋ ๊ณ์ํด์ ๋ฐ์ ํ๊ณ ์์ด. ์ต๊ทผ ๋ช ๋ ๊ฐ ์ถ๊ฐ๋ ์ฃผ์ ๊ธฐ๋ฅ๋ค์ ์ดํด๋ณด์. ๐TypeScript 5.0 (2023๋ 3์)
ํ์ ์คํฌ๋ฆฝํธ 5.0์ ์ ๋ง ํฐ ๋ณํ๊ฐ ์์์ด. ๋ฉ์ด์ ๋ฒ์ ์ ๋ฐ์ดํธ๋ต๊ฒ ๋ง์ด์ง.1. Decorators (๋ฐ์ฝ๋ ์ดํฐ) ์ ์ ์ง์
๋๋์ด ECMAScript ํ์ค์ ๋ง์ถฐ์ง ๋ฐ์ฝ๋ ์ดํฐ๊ฐ ์ ์์ผ๋ก ์ง์๋์ด. ์ด์ ๊น์ง๋ ์คํ์ ๊ธฐ๋ฅ์ด์๋๋ฐ, ์ด์ ๋ ์์ ์ ์ผ๋ก ์ฌ์ฉํ ์ ์์ง:
function logged(target: any, propertyKey: string, descriptor: PropertyDescriptor) {
const original = descriptor.value;
descriptor.value = function(...args: any[]) {
console.log(`Calling ${propertyKey} with`, args);
return original.apply(this, args);
};
return descriptor;
}
class Calculator {
@logged
add(a: number, b: number) {
return a + b;
}
}
์ ๋ค๋ฆญ ํ์ ๋งค๊ฐ๋ณ์๋ฅผ
const๋ก ์ ์ธํ ์ ์๊ฒ ๋์ด. ์ด๊ฒ ๋ญ๊ฐ ์ข๋๋ฉด, ํ์
์ถ๋ก ์ด ๋ ์ ํํด์ ธ:
function identity<const T>(value: T): T {
return value;
}
const result = identity({ name: "Alice", age: 30 });
// ํ์
์ด { name: string; age: number; }๊ฐ ์๋๋ผ
// { readonly name: "Alice"; readonly age: 30; }๋ก ์ถ๋ก ๋จ
ํ์ ์คํฌ๋ฆฝํธ 5.0์์๋ ๋ด๋ถ ๊ตฌ์กฐ๋ฅผ ๋ํญ ๊ฐ์ ํด์ ์ปดํ์ผ ์๋๊ฐ ํฌ๊ฒ ๋นจ๋ผ์ก์ด. ํนํ ๋๊ท๋ชจ ํ๋ก์ ํธ์์ ์ฒด๊ฐํ ์ ์๋ ์์ค์ด์ผ. โก
TypeScript 5.1 (2023๋ 6์)
1. Easier Implicit Returns for undefined-returning Functionsundefined๋ฅผ ๋ฐํํ๋ ํจ์์์ ๋ช
์์ ์ผ๋ก return์ ์ฐ์ง ์์๋ ๋๊ฒ ๊ฐ์ ๋์ด:
function logMessage(message: string): undefined {
console.log(message);
// return undefined; ๋ฅผ ์ฐ์ง ์์๋ OK!
}
getter์ setter์ ํ์ ์ด ๋ฌ๋ผ๋ ๋๊ฒ ๋์ด. ์ด๊ฒ ์ค๋ฌด์์ ๊ฝค ์ ์ฉํด:
class Thing {
#size = 0;
get size(): number {
return this.#size;
}
set size(value: number | string | boolean) {
let num = Number(value);
if (!Number.isFinite(num)) {
this.#size = 0;
return;
}
this.#size = num;
}
}
TypeScript 5.2 (2023๋ 8์)
1. using Declarations๋ฆฌ์์ค ๊ด๋ฆฌ๋ฅผ ์ํ
using ์ ์ธ์ด ์ถ๊ฐ๋์ด. ์ด๊ฑด ECMAScript์ Explicit Resource Management ์ ์์ ๋ฐ๋ฅธ ๊ฑฐ์ผ:
function doWork() {
using file = openFile("data.txt");
// file์ ์ฌ์ฉํ๋ ์์
๋ค...
// ํจ์๊ฐ ๋๋๋ฉด ์๋์ผ๋ก file์ด ์ ๋ฆฌ๋จ
}
๋ฐ์ฝ๋ ์ดํฐ์์ ๋ฉํ๋ฐ์ดํฐ๋ฅผ ๋ ์ฝ๊ฒ ๋ค๋ฃฐ ์ ์๊ฒ ๋์ด. ์ด๊ฑด ํนํ ์์กด์ฑ ์ฃผ์ ๊ฐ์ ํจํด์์ ์ ์ฉํด.
TypeScript 5.3 (2023๋ 11์)
1. Import AttributesJSON ๊ฐ์ ๋น-JavaScript ๋ชจ๋์ importํ ๋ ์์ฑ์ ์ง์ ํ ์ ์๊ฒ ๋์ด:
import data from "./data.json" with { type: "json" };
switch (true) ํจํด์์ ํ์
์ขํ๊ธฐ๊ฐ ๋ ์ ์๋ํ๊ฒ ๊ฐ์ ๋์ด.TypeScript 5.4 (2024๋ 3์)
1. NoInfer Utility Typeํ์ ์ถ๋ก ์ ์ ์ดํ ์ ์๋ ์๋ก์ด ์ ํธ๋ฆฌํฐ ํ์ ์ด ์ถ๊ฐ๋์ด:
function createStreetLight<C extends string>(
colors: C[],
defaultColor?: NoInfer<C>
) {
// ...
}
createStreetLight(["red", "yellow", "green"], "blue");
// ์๋ฌ! "blue"๋ colors ๋ฐฐ์ด์ ์์
ํด๋ก์ ๋ด๋ถ์์ ํ์ ์ขํ๊ธฐ๊ฐ ๋ ์ ์ ์ง๋๊ฒ ๊ฐ์ ๋์ด. ์ด์ ์๋ ํด๋ก์ ์์์ ํ์ ์ด ๋ค์ ๋์ด์ง๋ ๋ฌธ์ ๊ฐ ์์๋๋ฐ, ์ด์ ๋ ๊ทธ๋ฐ ๋ฌธ์ ๊ฐ ๋ง์ด ํด๊ฒฐ๋์ง.
TypeScript 5.5 (2024๋ 6์)
1. Inferred Type Predicatesํ์ ๊ฐ๋ ํจ์์์ ๋ฐํ ํ์ ์ ์๋์ผ๋ก ์ถ๋ก ํด์ค:
function isString(value: unknown) {
return typeof value === "string";
// ๋ฐํ ํ์
์ด ์๋์ผ๋ก 'value is string'์ผ๋ก ์ถ๋ก ๋จ
}
const values = ["hello", 42, "world", true];
const strings = values.filter(isString);
// strings์ ํ์
์ด string[]๋ก ์ ํํ ์ถ๋ก ๋จ!
์์ ์ธ๋ฑ์ค ์ ๊ทผ์์ ์ ์ด ํ๋ฆ ๋ถ์์ด ๊ฐ์ ๋์ด. ์ด๊ฒ ๋ฌด์จ ๋ง์ด๋๋ฉด:
function processData(data: { status: "success"; value: number } | { status: "error"; error: string }) {
const status = data.status;
if (status === "success") {
console.log(data.value); // ์ด์ ์๋ฌ๊ฐ ์ ๋จ!
}
}
๐ฎ ์ฐจ์ธ๋ ํ์ ์์คํ ๋ฐ์ ๋ฐฉํฅ
์, ์ด์ ๊ฐ์ฅ ํฅ๋ฏธ๋ก์ด ๋ถ๋ถ์ด์ผ. ํ์ ์คํฌ๋ฆฝํธ์ ๋ฏธ๋๋ ์ด๋ป๊ฒ ๋ ๊น? ํ์ฌ ๋ ผ์๋๊ณ ์๋ ๊ฒ๋ค๊ณผ ์์๋๋ ๋ฐ์ ๋ฐฉํฅ์ ์ดํด๋ณด์. ๐1. ๋ ๊ฐ๋ ฅํ ํ์ ์ถ๋ก
ํ์ ์คํฌ๋ฆฝํธ ํ์ ๊ณ์ํด์ ํ์ ์ถ๋ก ์ ๊ฐ์ ํ๊ณ ์์ด. ํนํ ๋ค์๊ณผ ๊ฐ์ ๋ฐฉํฅ์ผ๋ก ๋ฐ์ ํ๊ณ ์์ง:Higher-Kinded Types (๊ณ ์ฐจ ํ์ )
ํ์ฌ ํ์ ์คํฌ๋ฆฝํธ๋ ๊ณ ์ฐจ ํ์ ์ ์์ ํ ์ง์ํ์ง ์์. ํ์ง๋ง ์ปค๋ฎค๋ํฐ์์๋ ์ด์ ๋ํ ์๊ตฌ๊ฐ ๊ณ์๋๊ณ ์๊ณ , ๋ถ๋ถ์ ์ผ๋ก๋๋ง ์ง์๋ ๊ฐ๋ฅ์ฑ์ด ์์ด:
// ํ์ฌ๋ ๋ถ๊ฐ๋ฅํ์ง๋ง, ๋ฏธ๋์๋ ๊ฐ๋ฅํ ์๋?
type Functor<F> = {
map: <A, B>(fa: F<A>, f: (a: A) => B) => F<B>;
};
// ์ด๋ ๊ฒ Array, Promise ๋ฑ์ ๊ณตํต์ผ๋ก ์ ์ฉํ ์ ์๋
// ์ถ์ํ๊ฐ ๊ฐ๋ฅํด์ง ์ ์์ด
ํ์ ์คํฌ๋ฆฝํธ์ ์ ์ด ํ๋ฆ ๋ถ์์ ์ด๋ฏธ ๊ฐ๋ ฅํ์ง๋ง, ์์ผ๋ก ๋ ๋ฐ์ ํ ๊ฑฐ์ผ. ์๋ฅผ ๋ค์ด, ๋ ๋ณต์กํ ์กฐ๊ฑด๋ฌธ์ด๋ ๋ฃจํ์์๋ ํ์ ์ ์ ํํ ์ถ๋ก ํ ์ ์๊ฒ ๋ ๊ฑฐ์ผ.
2. ์ฑ๋ฅ ์ต์ ํ
๋๊ท๋ชจ ํ๋ก์ ํธ์์ ํ์ ์ฒดํน ์๋๋ ์ ๋ง ์ค์ํด. ํ์ ์คํฌ๋ฆฝํธ ํ์ ๊ณ์ํด์ ์ฑ๋ฅ์ ๊ฐ์ ํ๊ณ ์์ด:์ฆ๋ถ ์ปดํ์ผ ๊ฐ์
๋ณ๊ฒฝ๋ ํ์ผ๋ง ๋ค์ ์ฒดํฌํ๋ ์ฆ๋ถ ์ปดํ์ผ์ด ๋์ฑ ๋๋ํด์ง ๊ฑฐ์ผ. ํ์ฌ๋
--incremental ํ๋๊ทธ๊ฐ ์์ง๋ง, ์์ผ๋ก๋ ๋ ์ ๊ตํด์ง ์์ ์ด์ผ.๋ณ๋ ฌ ์ฒ๋ฆฌ
๋ฉํฐ์ฝ์ด CPU๋ฅผ ๋ ํจ์จ์ ์ผ๋ก ํ์ฉํด์ ํ์ ์ฒดํน์ ๋ณ๋ ฌ๋ก ์ฒ๋ฆฌํ๋ ๋ฐฉํฅ์ผ๋ก ๋ฐ์ ํ ๊ฑฐ์ผ. ์ด๋ฏธ ์ผ๋ถ ์คํ์ ๊ธฐ๋ฅ์ด ์๊ณ , ์์ผ๋ก ๋ ๊ฐ์ ๋ ์์ ์ด์ผ. โก
3. ๋ ๋์ ์๋ฌ ๋ฉ์์ง
ํ์ ์๋ฌ ๋ฉ์์ง๊ฐ ๋ ์น์ ํ๊ณ ์ดํดํ๊ธฐ ์ฌ์์ง ๊ฑฐ์ผ. ํ์ฌ๋ ๋ง์ด ๊ฐ์ ๋์ง๋ง, ๋ณต์กํ ์ ๋ค๋ฆญ ํ์ ์์๋ ์ฌ์ ํ ์๋ฌ ๋ฉ์์ง๊ฐ ๋ํดํ ๋๊ฐ ์๊ฑฐ๋ :Type 'Promise<{ data: User[] }>' is not assignable to type 'Promise<{ data: User[] | undefined }>'...๋ฏธ๋์ ์๋ฌ ๋ฉ์์ง (๊ฐ์ ๋จ)
๐ก API ์๋ต ํ์
์ด ์ผ์นํ์ง ์์ต๋๋ค. User ๋ฐฐ์ด์ด undefined์ผ ์ ์๋์ง ํ์ธํด์ฃผ์ธ์.๐ src/api/users.ts:42:10
4. ๋ฐํ์ ํ์ ๊ฒ์ฆ๊ณผ์ ํตํฉ
ํ์ฌ ํ์ ์คํฌ๋ฆฝํธ์ ํ์ ์ ์ปดํ์ผ ํ์์๋ง ์กด์ฌํ๊ณ ๋ฐํ์์๋ ์ฌ๋ผ์ ธ. ํ์ง๋ง ์์ผ๋ก๋ ๋ฐํ์ ํ์ ๊ฒ์ฆ๊ณผ ๋ ๊ธด๋ฐํ๊ฒ ํตํฉ๋ ๊ฐ๋ฅ์ฑ์ด ์์ด:Type Guards ์๋ ์์ฑ
ํ์ ์ ์๋ก๋ถํฐ ๋ฐํ์ ๊ฒ์ฆ ์ฝ๋๋ฅผ ์๋์ผ๋ก ์์ฑํ๋ ๊ธฐ๋ฅ์ด ์ถ๊ฐ๋ ์ ์์ด:
// ๋ฏธ๋์๋ ์ด๋ฐ ์์ผ๋ก?
interface User {
name: string;
age: number;
email: string;
}
// ์๋์ผ๋ก ๋ฐํ์ ๊ฒ์ฆ ํจ์ ์์ฑ
const validateUser = generateValidator<User>();
const data = await fetch("/api/user").then(r => r.json());
if (validateUser(data)) {
// data๊ฐ User ํ์
์์ด ๋ณด์ฅ๋จ
console.log(data.name);
}
5. ๋ ๋์ ๋ชจ๋ ์์คํ ์ง์
ECMAScript ๋ชจ๋ ์์คํ ์ด ๊ณ์ ๋ฐ์ ํ๊ณ ์๊ณ , ํ์ ์คํฌ๋ฆฝํธ๋ ์ด์ ๋ง์ถฐ ๋ฐ์ ํ ๊ฑฐ์ผ:Import Attributes ํ์ฅ
๋ค์ํ ์ข ๋ฅ์ ๋ชจ๋์ ๋ ์์ ํ๊ฒ importํ ์ ์๊ฒ ๋ ๊ฑฐ์ผ. JSON, CSS, WebAssembly ๋ฑ๋ฑ.
Package Exports ๊ฐ์
package.json์ exports ํ๋๋ฅผ ๋ ์ ์ง์ํ๊ฒ ๋ ๊ฑฐ์ผ. ์ด๋ฏธ ๋ง์ด ๊ฐ์ ๋์ง๋ง, ์์ผ๋ก ๋ ์ข์์ง ์์ ์ด์ผ. ๐ฆ
๐ฏ ์ค๋ฌด์์์ ํ์ ์คํฌ๋ฆฝํธ ํ์ฉ ํจํด
์ด๋ก ์ ์ถฉ๋ถํ ๋ดค์ผ๋, ์ด์ ์ค๋ฌด์์ ์ด๋ป๊ฒ ํ์ ์คํฌ๋ฆฝํธ๋ฅผ ํจ๊ณผ์ ์ผ๋ก ํ์ฉํ ์ ์๋์ง ์ดํด๋ณด์. ๐ผ1. API ์๋ต ํ์ ์ ์
๋ฐฑ์๋ API์ ํต์ ํ ๋ ํ์ ์ ์ ์ ์ํ๋ ๊ฒ ์ ๋ง ์ค์ํด. ์ด๋ ๊ฒ ํ๋ฉด API ์๋ต ๊ตฌ์กฐ๊ฐ ๋ฐ๋์์ ๋ ๋ฐ๋ก ์ ์ ์๊ฑฐ๋ :// API ์๋ต ํ์
์ ์
interface ApiResponse<T> {
success: boolean;
data?: T;
error?: {
code: string;
message: string;
};
}
interface User {
id: number;
name: string;
email: string;
createdAt: string;
}
// API ํจ์
async function fetchUser(id: number): Promise<ApiResponse<User>> {
const response = await fetch(`/api/users/${id}`);
return response.json();
}
// ์ฌ์ฉ
const result = await fetchUser(123);
if (result.success && result.data) {
console.log(result.data.name); // ํ์
์์ !
}
2. ์ ํธ๋ฆฌํฐ ํ์ ํ์ฉ
ํ์ ์คํฌ๋ฆฝํธ์๋ ์ ๋ง ์ ์ฉํ ๋ด์ฅ ์ ํธ๋ฆฌํฐ ํ์ ๋ค์ด ๋ง์. ์ด๊ฑธ ์ ํ์ฉํ๋ฉด ์ฝ๋๊ฐ ํจ์ฌ ๊น๋ํด์ ธ:Partial - ๋ชจ๋ ์์ฑ์ ์ ํ์ ์ผ๋ก
interface User {
id: number;
name: string;
email: string;
age: number;
}
// ์ฌ์ฉ์ ์ ๋ณด ์
๋ฐ์ดํธ ํจ์
function updateUser(id: number, updates: Partial<User>) {
// updates๋ User์ ์ผ๋ถ ์์ฑ๋ง ๊ฐ์ง ์ ์์
}
updateUser(123, { name: "Alice" }); // OK
updateUser(123, { age: 30 }); // OK
type UserPreview = Pick<User, "id" | "name">;
// { id: number; name: string; }
function showUserPreview(user: UserPreview) {
console.log(`${user.id}: ${user.name}`);
}
type UserWithoutId = Omit<User, "id">;
// { name: string; email: string; age: number; }
function createUser(userData: UserWithoutId): User {
return {
id: generateId(),
...userData
};
}
type UserRole = "admin" | "user" | "guest";
const permissions: Record<UserRole, string[]> = {
admin: ["read", "write", "delete"],
user: ["read", "write"],
guest: ["read"]
};
3. ์ ๋ค๋ฆญ ํ์ฉ ํจํด
์ ๋ค๋ฆญ์ ํ์ ์คํฌ๋ฆฝํธ์ ๊ฝ์ด์ผ. ์ฌ์ฌ์ฉ ๊ฐ๋ฅํ ์ปดํฌ๋ํธ๋ฅผ ๋ง๋ค ๋ ํ์์ ์ด์ง:์ ๋ค๋ฆญ ํจ์
// ๋ฐฐ์ด์ ์ฒซ ๋ฒ์งธ ์์๋ฅผ ๋ฐํํ๋ ํจ์
function first<T>(arr: T[]): T | undefined {
return arr[0];
}
const numbers = [1, 2, 3];
const firstNum = first(numbers); // number | undefined
const strings = ["a", "b", "c"];
const firstStr = first(strings); // string | undefined
class DataStore<T> {
private data: T[] = [];
add(item: T): void {
this.data.push(item);
}
get(index: number): T | undefined {
return this.data[index];
}
getAll(): T[] {
return [...this.data];
}
}
const userStore = new DataStore<User>();
userStore.add({ id: 1, name: "Alice", email: "alice@example.com", age: 30 });
const productStore = new DataStore<Product>();
productStore.add({ id: 1, name: "Laptop", price: 1000 });
// T๋ ๋ฐ๋์ id ์์ฑ์ ๊ฐ์ ธ์ผ ํจ
function findById<T extends { id: number }>(items: T[], id: number): T | undefined {
return items.find(item => item.id === id);
}
const users: User[] = [
{ id: 1, name: "Alice", email: "alice@example.com", age: 30 },
{ id: 2, name: "Bob", email: "bob@example.com", age: 25 }
];
const user = findById(users, 1); // User | undefined
4. ํ์ ๊ฐ๋ ํจํด
๋ฐํ์์ ํ์ ์ ์ฒดํฌํ๊ณ ํ์ ์ ์ขํ๋ ํจํด์ด์ผ. ์ ๋ง ์ ์ฉํด:typeof ํ์ ๊ฐ๋
function processValue(value: string | number) {
if (typeof value === "string") {
// ์ฌ๊ธฐ์๋ value๊ฐ string
console.log(value.toUpperCase());
} else {
// ์ฌ๊ธฐ์๋ value๊ฐ number
console.log(value.toFixed(2));
}
}
class Dog {
bark() {
console.log("Woof!");
}
}
class Cat {
meow() {
console.log("Meow!");
}
}
function makeSound(animal: Dog | Cat) {
if (animal instanceof Dog) {
animal.bark();
} else {
animal.meow();
}
}
interface Fish {
swim: () => void;
}
interface Bird {
fly: () => void;
}
// ํ์
๊ฐ๋ ํจ์
function isFish(pet: Fish | Bird): pet is Fish {
return (pet as Fish).swim !== undefined;
}
function move(pet: Fish | Bird) {
if (isFish(pet)) {
pet.swim();
} else {
pet.fly();
}
}
5. Discriminated Unions (ํ๋ณ๋ ์ ๋์จ)
์ด๊ฑด ์ ๋ง ๊ฐ๋ ฅํ ํจํด์ด์ผ. ์ํ ๊ด๋ฆฌ๋ ์๋ฌ ํธ๋ค๋ง์์ ํนํ ์ ์ฉํด:type LoadingState = {
status: "loading";
};
type SuccessState<T> = {
status: "success";
data: T;
};
type ErrorState = {
status: "error";
error: string;
};
type AsyncState<T> = LoadingState | SuccessState<T> | ErrorState;
function renderUser(state: AsyncState<User>) {
switch (state.status) {
case "loading":
return "Loading...";
case "success":
return `User: ${state.data.name}`; // state.data๊ฐ ์กด์ฌํจ์ ๋ณด์ฅ
case "error":
return `Error: ${state.error}`; // state.error๊ฐ ์กด์ฌํจ์ ๋ณด์ฅ
}
}
status ํ๋๋ฅผ ์ฒดํฌํ๋ฉด ํ์
์คํฌ๋ฆฝํธ๊ฐ ์๋์ผ๋ก ๋ค๋ฅธ ํ๋๋ค์ ํ์
์ ์ขํ์ค๋ค๋ ๊ฑฐ์ผ. ์ ๋ง ๋๋ํ์ง? ๐ง
โ ๏ธ ํ์ ์คํฌ๋ฆฝํธ ์ํฐํจํด๊ณผ ์ฃผ์์ฌํญ
ํ์ ์คํฌ๋ฆฝํธ๋ฅผ ์ฌ์ฉํ๋ฉด์ ํผํด์ผ ํ ํจํด๋ค๋ ์์๋๋ ๊ฒ ์ค์ํด. ์ด๋ฐ ์ค์๋ค์ ์ด๋ณด์๋ฟ๋ง ์๋๋ผ ๊ฒฝํ ์๋ ๊ฐ๋ฐ์๋ค๋ ์์ฃผ ํ๊ฑฐ๋ . ๐ซ1. any ํ์ ๋จ์ฉ
any๋ ํ์
์คํฌ๋ฆฝํธ์ ํ์
์์คํ
์ ์์ ํ ๋ฌด๋ ฅํ์์ผ. ์ ๋ง ํ์ํ ๊ฒฝ์ฐ๊ฐ ์๋๋ฉด ์ฌ์ฉํ์ง ๋ง์:
// โ ๋์ ์
function processData(data: any) {
return data.value.toString(); // ๋ฐํ์ ์๋ฌ ๊ฐ๋ฅ์ฑ
}
// โ
์ข์ ์
function processData(data: { value: number | string }) {
return data.value.toString(); // ํ์
์์
}
// ๋๋ ์ ๋ค๋ฆญ ์ฌ์ฉ
function processData<T extends { value: number | string }>(data: T) {
return data.value.toString();
}
any ๋์ unknown์ ์ฌ์ฉํ๋ ๊ฒ๋ ์ข์ ๋ฐฉ๋ฒ์ด์ผ. unknown์ ํ์
์ ์ฒดํฌํ๊ธฐ ์ ๊น์ง๋ ์๋ฌด๊ฒ๋ ํ ์ ์๊ฒ ๋ง๋ค์ด:2. ํ์ ๋จ์ธ(Type Assertion) ๊ณผ๋ค ์ฌ์ฉ
ํ์ ๋จ์ธ(as)์ "๋ด๊ฐ ํ์
์คํฌ๋ฆฝํธ๋ณด๋ค ๋ ์ ์์!"๋ผ๊ณ ์ ์ธํ๋ ๊ฑฐ์ผ. ํ์ง๋ง ์ด๊ฒ ํ๋ ธ์ ๋ ๋ฌธ์ ๊ฐ ์๊ธฐ์ง:
// โ ๋์ ์
const data = JSON.parse(jsonString) as User;
// JSON์ด ์ ๋ง User ํํ์ผ๊น? ๋ณด์ฅํ ์ ์์
// โ
์ข์ ์
function isUser(obj: any): obj is User {
return (
typeof obj === "object" &&
typeof obj.id === "number" &&
typeof obj.name === "string" &&
typeof obj.email === "string"
);
}
const data = JSON.parse(jsonString);
if (isUser(data)) {
// ์ด์ ์์ ํ๊ฒ ์ฌ์ฉ ๊ฐ๋ฅ
console.log(data.name);
}
3. ํ์ ๊ณผ ์ธํฐํ์ด์ค ํผ์ฉ
type๊ณผ interface๋ ๋น์ทํ์ง๋ง ์ฐจ์ด๊ฐ ์์ด. ์ผ๊ด์ฑ ์๊ฒ ์ฌ์ฉํ๋ ๊ฒ ์ข์:์ธํฐํ์ด์ค๋ฅผ ์ฌ์ฉํ๋ ๊ฒ ์ข์ ๊ฒฝ์ฐ:
- ๊ฐ์ฒด์ ํํ๋ฅผ ์ ์ํ ๋
- ํ์ฅ(extends)์ด ํ์ํ ๋
- ์ ์ธ ๋ณํฉ(Declaration Merging)์ด ํ์ํ ๋
ํ์ ์ ์ฌ์ฉํ๋ ๊ฒ ์ข์ ๊ฒฝ์ฐ:
- ์ ๋์จ ํ์ ์ด๋ ๊ต์ฐจ ํ์ ์ ๋ง๋ค ๋
- ํํ์ด๋ ํจ์ ํ์ ์ ์ ์ํ ๋
- ๋งคํ๋ ํ์ ์ด๋ ์กฐ๊ฑด๋ถ ํ์ ์ ์ฌ์ฉํ ๋
// ๊ฐ์ฒด ํํ ์ ์ - interface ์ ํธ
interface User {
id: number;
name: string;
}
// ์ ๋์จ ํ์
- type ์ฌ์ฉ
type Status = "pending" | "success" | "error";
// ํจ์ ํ์
- type ์ฌ์ฉ
type Callback = (data: string) => void;
4. ๋ถํ์ํ ํ์ ์ ์
ํ์ ์คํฌ๋ฆฝํธ์ ํ์ ์ถ๋ก ์ด ์ถฉ๋ถํ ๋๋ํ๋๊น, ๋ช ๋ฐฑํ ๊ฒฝ์ฐ์๋ ํ์ ์ ์๋ตํ๋ ๊ฒ ์คํ๋ ค ์ข์:// โ ๋ถํ์ํ ํ์
๋ช
์
const name: string = "Alice";
const age: number = 30;
const isActive: boolean = true;
// โ
ํ์
์ถ๋ก ํ์ฉ
const name = "Alice"; // string์ผ๋ก ์ถ๋ก
const age = 30; // number๋ก ์ถ๋ก
const isActive = true; // boolean์ผ๋ก ์ถ๋ก
// ํ์ง๋ง ํจ์ ๋งค๊ฐ๋ณ์๋ ๋ช
์ํ๋ ๊ฒ ์ข์
function greet(name: string) { // ์ด๊ฑด ๋ช
์ํด์ผ ํจ
return `Hello, ${name}!`;
}
5. ํ์ ์ ์ ํ์ผ ๊ด๋ฆฌ ์ํ
๋๊ท๋ชจ ํ๋ก์ ํธ์์๋ ํ์ ์ ์๋ฅผ ์ ๊ด๋ฆฌํ๋ ๊ฒ ์ ๋ง ์ค์ํด. ํ์ ์ ์ ํ์ผ์ ์ฒด๊ณ์ ์ผ๋ก ๊ตฌ์กฐํํ์:// types/user.ts
export interface User {
id: number;
name: string;
email: string;
}
export type UserRole = "admin" | "user" | "guest";
// types/api.ts
export interface ApiResponse<T> {
success: boolean;
data?: T;
error?: ApiError;
}
export interface ApiError {
code: string;
message: string;
}
// types/index.ts
export * from "./user";
export * from "./api";
2. ๊ณตํต์ผ๋ก ์ฌ์ฉ๋๋ ํ์ ์ ๋ณ๋ ํ์ผ๋ก ๊ด๋ฆฌ
3. ํ์ ์ด๋ฆ์ ๋ช ํํ๊ณ ์ผ๊ด์ฑ ์๊ฒ
4. JSDoc ์ฃผ์์ผ๋ก ํ์ ์ ๋ํ ์ค๋ช ์ถ๊ฐ
5. ๋๋ฌด ๋ณต์กํ ํ์ ์ ์ฌ๋ฌ ๊ฐ๋ก ๋ถ๋ฆฌํ๋ ๊ฒ ์ข์ ๐
๐ ๏ธ ํ์ ์คํฌ๋ฆฝํธ ๊ฐ๋ฐ ํ๊ฒฝ ์ต์ ํ
ํ์ ์คํฌ๋ฆฝํธ๋ฅผ ํจ์จ์ ์ผ๋ก ์ฌ์ฉํ๋ ค๋ฉด ๊ฐ๋ฐ ํ๊ฒฝ ์ค์ ๋ ์ค์ํด. ๋ช ๊ฐ์ง ํ์ ๊ณต์ ํ ๊ฒ. โ๏ธ1. tsconfig.json ์ค์
tsconfig.json์ ํ์
์คํฌ๋ฆฝํธ ํ๋ก์ ํธ์ ํต์ฌ ์ค์ ํ์ผ์ด์ผ. ์ ๋๋ก ์ค์ ํ๋ฉด ๊ฐ๋ฐ ๊ฒฝํ์ด ํจ์ฌ ์ข์์ ธ:
{
"compilerOptions": {
// ์๊ฒฉํ ํ์
์ฒดํน ํ์ฑํ
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"strictBindCallApply": true,
"strictPropertyInitialization": true,
"noImplicitThis": true,
"alwaysStrict": true,
// ์ถ๊ฐ ์ฒดํฌ
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
// ๋ชจ๋ ์ค์
"module": "ESNext",
"moduleResolution": "bundler",
"target": "ES2022",
// ๊ฒฝ๋ก ๋ณ์นญ
"baseUrl": ".",
"paths": {
"@/*": ["src/*"],
"@components/*": ["src/components/*"],
"@utils/*": ["src/utils/*"]
},
// ๊ธฐํ
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist"]
}
2. ESLint์ Prettier ํตํฉ
ํ์ ์คํฌ๋ฆฝํธ์ ESLint, Prettier๋ฅผ ํจ๊ป ์ฌ์ฉํ๋ฉด ์ฝ๋ ํ์ง์ด ํฌ๊ฒ ํฅ์๋ผ:// .eslintrc.json
{
"parser": "@typescript-eslint/parser",
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking",
"prettier"
],
"plugins": ["@typescript-eslint"],
"parserOptions": {
"project": "./tsconfig.json"
},
"rules": {
"@typescript-eslint/no-unused-vars": "error",
"@typescript-eslint/no-explicit-any": "warn",
"@typescript-eslint/explicit-function-return-type": "off"
}
}
3. VS Code ํ์ฅ ํ๋ก๊ทธ๋จ
VS Code๋ฅผ ์ฌ์ฉํ๋ค๋ฉด ์ด ํ์ฅ ํ๋ก๊ทธ๋จ๋ค์ ํ์์ผ:ESLint Prettier Error Lens Pretty TypeScript Errors TypeScript Importer
ํนํ Pretty TypeScript Errors๋ ๋ณต์กํ ํ์ ์๋ฌ๋ฅผ ์ฝ๊ธฐ ์ฝ๊ฒ ๋ง๋ค์ด์ค์ ์ ๋ง ์ ์ฉํด. โจ
4. ๋น๋ ๋๊ตฌ ์ค์
Vite ์ฌ์ฉ ์// vite.config.ts
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import path from 'path';
export default defineConfig({
plugins: [react()],
resolve: {
alias: {
'@': path.resolve(__dirname, './src'),
'@components': path.resolve(__dirname, './src/components'),
'@utils': path.resolve(__dirname, './src/utils')
}
},
build: {
target: 'es2022',
sourcemap: true
}
});
// webpack.config.js
module.exports = {
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/
}
]
},
resolve: {
extensions: ['.tsx', '.ts', '.js'],
alias: {
'@': path.resolve(__dirname, 'src/'),
'@components': path.resolve(__dirname, 'src/components/'),
'@utils': path.resolve(__dirname, 'src/utils/')
}
}
};
๐ ํ์ ์คํฌ๋ฆฝํธ ์ํ๊ณ์ ๋๊ตฌ๋ค
ํ์ ์คํฌ๋ฆฝํธ ์ฃผ๋ณ์๋ ์ ๋ง ํ๋ถํ ์ํ๊ณ๊ฐ ํ์ฑ๋์ด ์์ด. ์ ์ฉํ ๋๊ตฌ๋ค์ ์๊ฐํ ๊ฒ. ๐ง1. ํ์ ์ ์ ๋ผ์ด๋ธ๋ฌ๋ฆฌ
DefinitelyTyped (@types)์๋ฐ์คํฌ๋ฆฝํธ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ค์ ํ์ ์ ์๋ฅผ ์ ๊ณตํ๋ ๊ฑฐ๋ํ ์ ์ฅ์์ผ. npm์์
@types/ ์ ๋์ฌ๋ก ์ค์นํ ์ ์์ด:
npm install --save-dev @types/react
npm install --save-dev @types/node
npm install --save-dev @types/lodash
2. ๋ฐํ์ ํ์ ๊ฒ์ฆ ๋ผ์ด๋ธ๋ฌ๋ฆฌ
Zod๊ฐ์ฅ ์ธ๊ธฐ ์๋ ์คํค๋ง ๊ฒ์ฆ ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ผ. ํ์ ์คํฌ๋ฆฝํธ์ ์๋ฒฝํ๊ฒ ํตํฉ๋ผ:
import { z } from 'zod';
const UserSchema = z.object({
id: z.number(),
name: z.string(),
email: z.string().email(),
age: z.number().min(0).max(120)
});
type User = z.infer<typeof UserSchema>;
// ๋ฐํ์ ๊ฒ์ฆ
const result = UserSchema.safeParse(data);
if (result.success) {
const user: User = result.data;
console.log(user.name);
}
ํจ์ํ ํ๋ก๊ทธ๋๋ฐ ์คํ์ผ์ ํ์ ๊ฒ์ฆ ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ผ:
Yup
ํผ ๊ฒ์ฆ์ ํนํ๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ก, React Hook Form ๊ฐ์ ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ ์ ์ด์ธ๋ ค.
3. ์ ํธ๋ฆฌํฐ ๋ผ์ด๋ธ๋ฌ๋ฆฌ
type-festํ์ ์คํฌ๋ฆฝํธ ์ ํธ๋ฆฌํฐ ํ์ ๋ชจ์์ง์ด์ผ. ๋ด์ฅ ์ ํธ๋ฆฌํฐ ํ์ ๋ณด๋ค ๋ ๋ค์ํ ๊ธฐ๋ฅ์ ์ ๊ณตํด:
import type { Simplify, PartialDeep, ReadonlyDeep } from 'type-fest';
// ๋ณต์กํ ํ์
์ ๋จ์ํ
type SimplifiedUser = Simplify<User & UserProfile & UserSettings>;
// ๊น์ ๋ถ๋ถ ํ์
type PartialUser = PartialDeep<User>;
// ๊น์ ์ฝ๊ธฐ ์ ์ฉ
type ImmutableUser = ReadonlyDeep<User>;
ํจํด ๋งค์นญ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ก, ๋ณต์กํ ์กฐ๊ฑด ๋ถ๊ธฐ๋ฅผ ์ฐ์ํ๊ฒ ์ฒ๋ฆฌํ ์ ์์ด:
import { match } from 'ts-pattern';
const result = match(state)
.with({ status: 'loading' }, () => 'Loading...')
.with({ status: 'success' }, ({ data }) => `Success: ${data}`)
.with({ status: 'error' }, ({ error }) => `Error: ${error}`)
.exhaustive();
4. ๋ฌธ์ํ ๋๊ตฌ
TypeDocํ์ ์คํฌ๋ฆฝํธ ์ฝ๋๋ก๋ถํฐ ์๋์ผ๋ก ๋ฌธ์๋ฅผ ์์ฑํด์ฃผ๋ ๋๊ตฌ์ผ. JSDoc ์ฃผ์์ ๊ธฐ๋ฐ์ผ๋ก ์๋ํด:
/**
* ์ฌ์ฉ์ ์ ๋ณด๋ฅผ ๊ฐ์ ธ์ต๋๋ค.
* @param id - ์ฌ์ฉ์ ID
* @returns ์ฌ์ฉ์ ๊ฐ์ฒด ๋๋ undefined
* @example
* ```ts
* const user = await fetchUser(123);
* console.log(user?.name);
* ```
*/
async function fetchUser(id: number): Promise<User | undefined> {
// ...
}
5. ํ ์คํ ๋๊ตฌ
ts-jestJest์์ ํ์ ์คํฌ๋ฆฝํธ๋ฅผ ์ฌ์ฉํ ์ ์๊ฒ ํด์ฃผ๋ ํ๋ฆฌ์ ์ด์ผ:
Vitest
Vite ๊ธฐ๋ฐ์ ์ด๊ณ ์ ํ ์คํธ ๋ฌ๋๋ก, ํ์ ์คํฌ๋ฆฝํธ๋ฅผ ๊ธฐ๋ณธ ์ง์ํด. ์์ฆ ์ ๋ง ์ธ๊ธฐ๊ฐ ๋ง์. โก
๐ ํ์ ์คํฌ๋ฆฝํธ ๋ง์ด๊ทธ๋ ์ด์ ์ ๋ต
๊ธฐ์กด ์๋ฐ์คํฌ๋ฆฝํธ ํ๋ก์ ํธ๋ฅผ ํ์ ์คํฌ๋ฆฝํธ๋ก ์ ํํ๋ ๊ฑด ํฐ ๊ฒฐ์ ์ด์ผ. ๋จ๊ณ๋ณ๋ก ์ ๊ทผํ๋ ๊ฒ ์ค์ํด. ๐1. ์ ์ง์ ๋ง์ด๊ทธ๋ ์ด์
ํ ๋ฒ์ ๋ชจ๋ ๊ฑธ ๋ฐ๊พธ๋ ค๊ณ ํ์ง ๋ง. ์ ์ง์ ์ผ๋ก ์ ๊ทผํ๋ ๊ฒ ํจ์ฌ ์์ ํด:1๋จ๊ณ: ํ์ ์คํฌ๋ฆฝํธ ์ค์
// tsconfig.json (์ด๊ธฐ ์ค์ )
{
"compilerOptions": {
"allowJs": true, // JS ํ์ผ ํ์ฉ
"checkJs": false, // JS ํ์ผ ์ฒดํฌ ์ ํจ
"strict": false, // ์๊ฒฉ ๋ชจ๋ ๋นํ์ฑํ
"noEmit": true, // ์ปดํ์ผ ๊ฒฐ๊ณผ ์์ฑ ์ ํจ
"esModuleInterop": true,
"skipLibCheck": true
},
"include": ["src/**/*"]
}
.js ํ์ผ์ .ts๋ก, .jsx ํ์ผ์ .tsx๋ก ํ๋์ฉ ๋ณ๊ฒฝํด. ์ค์ํ ๊ฑด ์์ ํ์ผ๋ถํฐ ์์ํ๋ ๊ฑฐ์ผ.3๋จ๊ณ: ํ์ ์ถ๊ฐ
์๋ฌ๊ฐ ๋๋ ๋ถ๋ถ๋ถํฐ ํ์ ์ ์ถ๊ฐํด. ์ฒ์์๋
any๋ฅผ ์ฌ์ฉํด๋ ๊ด์ฐฎ์. ๋์ค์ ๊ฐ์ ํ๋ฉด ๋ผ.4๋จ๊ณ: ์๊ฒฉ ๋ชจ๋ ํ์ฑํ
๋ชจ๋ ํ์ผ์ด ํ์ ์คํฌ๋ฆฝํธ๋ก ์ ํ๋๋ฉด, ์ ์ง์ ์ผ๋ก ์๊ฒฉ ๋ชจ๋๋ฅผ ํ์ฑํํด:
// tsconfig.json (์ต์ข
์ค์ )
{
"compilerOptions": {
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
// ... ๋ค๋ฅธ ์๊ฒฉ ์ต์
๋ค
}
}
2. ๋ง์ด๊ทธ๋ ์ด์ ์ฐ์ ์์
์ด๋ค ํ์ผ๋ถํฐ ๋ง์ด๊ทธ๋ ์ด์ ํ ์ง ์ ๋ต์ ์ธ์ฐ๋ ๊ฒ ์ค์ํด:๋์ ์ฐ์ ์์:
1. ์ ํธ๋ฆฌํฐ ํจ์๋ค (์์กด์ฑ์ด ์ ์)
2. ํ์ ์ ์ ํ์ผ๋ค
3. ์์ ํ์ผ๋ค
4. ํต์ฌ ๋น์ฆ๋์ค ๋ก์ง
๋ฎ์ ์ฐ์ ์์:
1. ๋ ๊ฑฐ์ ์ฝ๋
2. ๊ณง ์ญ์ ๋ ์ฝ๋
3. ์ธ๋ถ ์์กด์ฑ์ด ๋ง์ ์ฝ๋
3. ํ ๊ต์ก
ํ์ ์คํฌ๋ฆฝํธ ๋์ ์ ๊ธฐ์ ์ ๋ฌธ์ ๋ง์ด ์๋์ผ. ํ ์ ์ฒด๊ฐ ํจ๊ป ๋ฐฐ์์ผ ํด:- ์ ๊ธฐ์ ์ธ ์คํฐ๋ ์ธ์ ์งํ
- ์ฝ๋ ๋ฆฌ๋ทฐ์์ ํ์ ๊ด๋ จ ํผ๋๋ฐฑ ๊ณต์
- ๋ฒ ์คํธ ํ๋ํฐ์ค ๋ฌธ์ํ
- ํ์ด ํ๋ก๊ทธ๋๋ฐ์ผ๋ก ์ง์ ๊ณต์
์ฌ๋ฅ๋ท์์ ํ์ ์คํฌ๋ฆฝํธ ์ ๋ฌธ๊ฐ์ ์ปจ์คํ ์ ๋ฐ๋ ๊ฒ๋ ์ข์ ๋ฐฉ๋ฒ์ด์ผ. ์ค์ ํ๋ก์ ํธ์ ์ ์ฉํ๋ฉด์ ๋ฐฐ์ฐ๋ ๊ฒ ๊ฐ์ฅ ํจ๊ณผ์ ์ด๊ฑฐ๋ . ๐ฅ
๐ก ๋ง์ด๊ทธ๋ ์ด์ ์ฒดํฌ๋ฆฌ์คํธ
โ ํ์ ์คํฌ๋ฆฝํธ ์ค์น ๋ฐ ์ค์ โ ๋น๋ ๋๊ตฌ ์ค์ (Webpack, Vite ๋ฑ)
โ ESLint, Prettier ์ค์
โ CI/CD ํ์ดํ๋ผ์ธ ์ ๋ฐ์ดํธ
โ ํ์ ์ ์ ํ์ผ ์ค์น (@types/*)
โ ํ ๊ต์ก ๋ฐ ๋ฌธ์ํ
โ ์ ์ง์ ๋ง์ด๊ทธ๋ ์ด์ ๊ณํ ์๋ฆฝ
โ ์ฝ๋ ๋ฆฌ๋ทฐ ํ๋ก์ธ์ค ์ ๋ฐ์ดํธ
โ ํ ์คํธ ํ๊ฒฝ ์ค์
โ ์ฑ๋ฅ ๋ชจ๋ํฐ๋ง ์ค์
๐ ํ์ ์คํฌ๋ฆฝํธ ํ์ต ๋ก๋๋งต
ํ์ ์คํฌ๋ฆฝํธ๋ฅผ ์ฒ์ ๋ฐฐ์ฐ๋ ์ฌ๋๋ค์ ์ํ ํ์ต ๋ก๋๋งต์ ์ ๋ฆฌํด๋ดค์ด. ๐์ด๊ธ ๋จ๊ณ (1-2๊ฐ์)
1์ฃผ์ฐจ: ๊ธฐ๋ณธ ํ์- ๊ธฐ๋ณธ ํ์ ๋ค (string, number, boolean, array, tuple)
- ํ์ ์ถ๋ก
- ํ์ ๋ช ์
- ํจ์ ํ์
2์ฃผ์ฐจ: ์ธํฐํ์ด์ค์ ํ์ ๋ณ์นญ
- interface vs type
- ๊ฐ์ฒด ํ์ ์ ์
- ์ ํ์ ์์ฑ
- ์ฝ๊ธฐ ์ ์ฉ ์์ฑ
3-4์ฃผ์ฐจ: ๊ณ ๊ธ ํ์
- ์ ๋์จ ํ์
- ๊ต์ฐจ ํ์
- ๋ฆฌํฐ๋ด ํ์
- ํ์ ๊ฐ๋
5-8์ฃผ์ฐจ: ์ค์ ํ๋ก์ ํธ
- ๊ฐ๋จํ Todo ์ฑ ๋ง๋ค๊ธฐ
- API ์ฐ๋ํ๊ธฐ
- ์ํ ๊ด๋ฆฌ (Context API)
- ํผ ์ฒ๋ฆฌ
์ค๊ธ ๋จ๊ณ (2-3๊ฐ์)
์ ๋ค๋ฆญ- ์ ๋ค๋ฆญ ํจ์
- ์ ๋ค๋ฆญ ํด๋์ค
- ์ ๋ค๋ฆญ ์ ์ฝ ์กฐ๊ฑด
- ์ ๋ค๋ฆญ ์ ํธ๋ฆฌํฐ ํ์
๊ณ ๊ธ ํ์ ๊ธฐ๋ฅ
- ์กฐ๊ฑด๋ถ ํ์
- ๋งคํ๋ ํ์
- ํ ํ๋ฆฟ ๋ฆฌํฐ๋ด ํ์
- infer ํค์๋
์ค์ ํจํด
- Discriminated Unions
- ํ์ ์ขํ๊ธฐ ํจํด
- ๋น๋ ํจํด
- ํฉํ ๋ฆฌ ํจํด
๊ณ ๊ธ ๋จ๊ณ (3๊ฐ์ ์ด์)
ํ์ ์์คํ ๊น์ด ์ดํด- ๊ตฌ์กฐ์ ํ์ดํ vs ๋ช ๋ชฉ์ ํ์ดํ
- ๊ณต๋ณ์ฑ๊ณผ ๋ฐ๊ณต๋ณ์ฑ
- ํ์ ํธํ์ฑ
- ํ์ ์์คํ ์ ํ๊ณ
๋๊ท๋ชจ ํ๋ก์ ํธ ๊ด๋ฆฌ
- ๋ชจ๋ ธ๋ ํฌ ๊ตฌ์กฐ
- ํ์ ์ ์ ๊ด๋ฆฌ
- ์ฑ๋ฅ ์ต์ ํ
- ๋ง์ด๊ทธ๋ ์ด์ ์ ๋ต
์ํ๊ณ ๋๊ตฌ ํ์ฉ
- Zod, io-ts ๊ฐ์ ๋ฐํ์ ๊ฒ์ฆ
- type-fest ๊ฐ์ ์ ํธ๋ฆฌํฐ
- TypeDoc์ผ๋ก ๋ฌธ์ํ
- ํ ์คํ ์ ๋ต
์ฑ : "์ดํํฐ๋ธ ํ์ ์คํฌ๋ฆฝํธ", "ํ์ ์คํฌ๋ฆฝํธ ํ๋ก๊ทธ๋๋ฐ"
์จ๋ผ์ธ ๊ฐ์: Udemy, ์ธํ๋ฐ, ๋ ธ๋ง๋์ฝ๋
์ฐ์ต: TypeScript Exercises, Type Challenges
์ปค๋ฎค๋ํฐ: TypeScript Discord, Reddit r/typescript
๊ทธ๋ฆฌ๊ณ ์ค์ ํ๋ก์ ํธ๋ฅผ ํ๋ฉด์ ๋งํ๋ ๋ถ๋ถ์ด ์๋ค๋ฉด, ์ฌ๋ฅ๋ท์์ ๋ฉํ ๋ฅผ ์ฐพ์๋ณด๋ ๊ฒ๋ ์ข์ ๋ฐฉ๋ฒ์ด์ผ! ๐ฏ
๐ฎ ํ์ ์คํฌ๋ฆฝํธ์ ๋ฏธ๋ ์ ๋ง
๋ง์ง๋ง์ผ๋ก ํ์ ์คํฌ๋ฆฝํธ์ ๋ฏธ๋์ ๋ํด ์ด์ผ๊ธฐํด๋ณด์. ์์ผ๋ก ์ด๋ป๊ฒ ๋ฐ์ ํ ๊น? ๐1. ECMAScript์์ ํตํฉ
ํ์ ์คํฌ๋ฆฝํธ๋ ๊ณ์ํด์ ECMAScript ํ์ค์ ๋ฐ๋ผ๊ฐ๊ณ ์์ด. ์ต๊ทผ์๋ ECMAScript ์ ์ ๋จ๊ณ์ ๊ธฐ๋ฅ๋ค๋ ๋น ๋ฅด๊ฒ ์ง์ํ๊ณ ์์ง. ์์ผ๋ก๋ ๋์ฑ ๊ธด๋ฐํ๊ฒ ํตํฉ๋ ๊ฑฐ์ผ.ํนํ ์ฃผ๋ชฉํ ๋งํ ๊ฑด Type Annotations Proposal์ด์ผ. ์ด๊ฑด ์๋ฐ์คํฌ๋ฆฝํธ ์์ฒด์ ํ์ ์ฃผ์์ ์ถ๊ฐํ์๋ ์ ์์ธ๋ฐ, ๋ง์ฝ ์ด๊ฒ ํ์คํ๋๋ฉด ํ์ ์คํฌ๋ฆฝํธ์ ์๋ฐ์คํฌ๋ฆฝํธ์ ๊ฒฝ๊ณ๊ฐ ๋์ฑ ํ๋ ค์ง ๊ฑฐ์ผ. ๐
2. ์ฑ๋ฅ ๊ฐ์
ํ์ ์คํฌ๋ฆฝํธ ํ์ ๊ณ์ํด์ ์ปดํ์ผ ์๋์ IDE ์ฑ๋ฅ์ ๊ฐ์ ํ๊ณ ์์ด. ํนํ ๋๊ท๋ชจ ํ๋ก์ ํธ์์์ ์ฑ๋ฅ์ด ํฌ๊ฒ ํฅ์๋ ์์ ์ด์ผ.- ๋ ๋๋ํ ์ฆ๋ถ ์ปดํ์ผ
- ๋ณ๋ ฌ ํ์ ์ฒดํน
- ๋ฉ๋ชจ๋ฆฌ ์ฌ์ฉ๋ ์ต์ ํ
- ์บ์ฑ ์ ๋ต ๊ฐ์
3. ๊ฐ๋ฐ์ ๊ฒฝํ ํฅ์
์๋ฌ ๋ฉ์์ง๊ฐ ๋ ์น์ ํด์ง๊ณ , IDE ํตํฉ์ด ๋ ๊ฐ๋ ฅํด์ง ๊ฑฐ์ผ. ํนํ AI ๊ธฐ๋ฐ ์ฝ๋ ์์ฑ๊ณผ ํ์ ์ถ๋ก ์ด ๋ฐ์ ํ๋ฉด์, ํ์ ์คํฌ๋ฆฝํธ ๊ฐ๋ฐ์ด ๋์ฑ ํธํด์ง ๊ฑฐ์ผ. ๐ค4. ์๋ก์ด ํ์ ์์คํ ๊ธฐ๋ฅ
์์ผ๋ก ์ถ๊ฐ๋ ๊ฐ๋ฅ์ฑ์ด ์๋ ๊ธฐ๋ฅ๋ค:- ๋ ๊ฐ๋ ฅํ ํ์ ์ถ๋ก
- ๊ณ ์ฐจ ํ์ ์ง์
- ์์กด ํ์ (Dependent Types) ๋ถ๋ถ ์ง์
- ๋ ์ ๊ตํ ์ ์ด ํ๋ฆ ๋ถ์
- ํจ๊ณผ ์์คํ (Effect System)
5. ์ํ๊ณ ํ์ฅ
ํ์ ์คํฌ๋ฆฝํธ ์ํ๊ณ๋ ๊ณ์ ์ฑ์ฅํ ๊ฑฐ์ผ. ํนํ ๋ค์ ๋ถ์ผ์์ ๋ ๋ง์ ๋ฐ์ ์ด ์์๋ผ:๋ฐฑ์๋: Node.js, Deno, Bun ๋ฑ์์ ํ์ ์คํฌ๋ฆฝํธ๊ฐ 1๊ธ ์๋ฏผ์ผ๋ก ์๋ฆฌ์ก๊ณ ์์ด.
๋ชจ๋ฐ์ผ: React Native, Ionic ๋ฑ์์ ํ์ ์คํฌ๋ฆฝํธ ์ฌ์ฉ์ด ํ์ค์ด ๋๊ณ ์์ด.
๋ฐ์คํฌํฑ: Electron, Tauri ๋ฑ์์๋ ํ์ ์คํฌ๋ฆฝํธ๊ฐ ๋๋ฆฌ ์ฌ์ฉ๋ผ.
ํด๋ผ์ฐ๋: AWS CDK, Pulumi ๊ฐ์ IaC ๋๊ตฌ๋ค๋ ํ์ ์คํฌ๋ฆฝํธ๋ฅผ ์ง์ํด. โ๏ธ
6. ๊ฒฝ์ ๊ธฐ์ ๋ค
ํ์ ์คํฌ๋ฆฝํธ์ ์ฑ๊ณต์ ๋ณด๊ณ ๋น์ทํ ์๋๋ค์ด ๋์ค๊ณ ์์ด:Flow: ํ์ด์ค๋ถ์ด ๋ง๋ ํ์ ์์คํ ์ด์ง๋ง, ํ์ ์คํฌ๋ฆฝํธ์ ๋ฐ๋ ค์ ์ฌ์ฉ๋ฅ ์ด ๋ง์ด ์ค์์ด.
ReScript: OCaml ๊ธฐ๋ฐ์ ํ์ ์์ ํ ์ธ์ด๋ก, ์๋ฐ์คํฌ๋ฆฝํธ๋ก ์ปดํ์ผ๋ผ. ํจ์ํ ํ๋ก๊ทธ๋๋ฐ ์ปค๋ฎค๋ํฐ์์ ์ธ๊ธฐ๊ฐ ์์ด.
Hegel: ๋ ๊ฐ๋ ฅํ ํ์ ์์คํ ์ ๋ชฉํ๋ก ํ๋ ํ๋ก์ ํธ์ผ.
ํ์ง๋ง ํ์ฌ๋ก์๋ ํ์ ์คํฌ๋ฆฝํธ์ ์ฐ์๊ฐ ํ๊ณ ํด. ์ํ๊ณ, ์ปค๋ฎค๋ํฐ, ๋๊ตฌ ์ง์ ๋ฉด์์ ์๋์ ์ด๊ฑฐ๋ . ๐
๐ฏ ๋ง๋ฌด๋ฆฌํ๋ฉฐ
์, ์ ๋ง ๊ธด ์ฌ์ ์ด์์ง? ํ์ ์คํฌ๋ฆฝํธ์ ๋ํด ์ ๋ง ๋ง์ ๊ฑธ ๋ค๋ค์ด. ๐ํ์ ์คํฌ๋ฆฝํธ๋ ๋จ์ํ ์๋ฐ์คํฌ๋ฆฝํธ์ ํ์ ์ ์ถ๊ฐํ ๊ฒ ์ด์์ด์ผ. ๋๊ท๋ชจ ์ ํ๋ฆฌ์ผ์ด์ ์ ์์ ํ๊ฒ ๊ฐ๋ฐํ ์ ์๊ฒ ํด์ฃผ๋ ๊ฐ๋ ฅํ ๋๊ตฌ์ด์, ๊ฐ๋ฐ์์ ์์ฐ์ฑ์ ํฌ๊ฒ ํฅ์์์ผ์ฃผ๋ ํ๋ซํผ์ด์ง.
ํต์ฌ ํฌ์ธํธ ์ ๋ฆฌ:
1. ํ์ ์์ ์ฑ: ์ปดํ์ผ ํ์์ ๋ฒ๊ทธ๋ฅผ ์ก์๋ผ ์ ์์ด
2. ๊ฐ๋ฐ ์์ฐ์ฑ: IDE ์ง์์ด ๋ฐ์ด๋๊ณ ๋ฆฌํฉํ ๋ง์ด ์์ ํด
3. ์ฝ๋ ํ์ง: ๋ช ์์ ์ธ ํ์ ์ผ๋ก ์ฝ๋ ์๋๊ฐ ๋ช ํํด์ ธ
4. ํ ํ์ : ํ์ ์ด ๋ฌธ์ ์ญํ ์ ํด์ ํ์ ์ด ์์ํด
5. ์ํ๊ณ: ํ๋ถํ ๋๊ตฌ์ ๋ผ์ด๋ธ๋ฌ๋ฆฌ ์ง์
ํ์ ์คํฌ๋ฆฝํธ๋ฅผ ๋ฐฐ์ฐ๋ ๊ฑด ์ฒ์์๋ ์ข ์ด๋ ค์ธ ์ ์์ด. ์๋ฐ์คํฌ๋ฆฝํธ์ ์์ ๋ก์์ ์ต์ํ๋ค๋ฉด ํ์ ์์คํ ์ด ๋ต๋ตํ๊ฒ ๋๊ปด์ง ์๋ ์์ง. ํ์ง๋ง ์กฐ๊ธ๋ง ์ต์ํด์ง๋ฉด, ํ์ ์คํฌ๋ฆฝํธ ์์ด๋ ๊ฐ๋ฐํ๊ธฐ ํ๋ค์ด์ง ๊ฑฐ์ผ. ์ ๋ง์ด์ผ! ๐ช
ํนํ ๋๊ท๋ชจ ํ๋ก์ ํธ๋ ํ ํ๋ก์ ํธ์์๋ ํ์ ์คํฌ๋ฆฝํธ์ ์ง๊ฐ๊ฐ ๋ฐํ๋ผ. ์ฝ๋๋ฒ ์ด์ค๊ฐ ์ปค์ง์๋ก, ํ์์ด ๋ง์์ง์๋ก, ํ์ ์คํฌ๋ฆฝํธ์ ๊ฐ์น๋ ๋์ฑ ๋น๋์ง.
์์ผ๋ก ํ์ ์คํฌ๋ฆฝํธ๋ ๊ณ์ ๋ฐ์ ํ ๊ฑฐ์ผ. ๋ ๊ฐ๋ ฅํ ํ์ ์์คํ , ๋ ๋น ๋ฅธ ์ปดํ์ผ ์๋, ๋ ๋์ ๊ฐ๋ฐ์ ๊ฒฝํ์ ์ ๊ณตํ๋ฉด์ ๋ง์ด์ง. ๊ทธ๋ฆฌ๊ณ ์๋ฐ์คํฌ๋ฆฝํธ ์ํ๊ณ์ ์ฌ์ค์ ํ์ค์ผ๋ก ์๋ฆฌ์ก์ ๊ฑฐ์ผ.
์ด์ ์ฌ๋ฌ๋ถ ์ฐจ๋ก์ผ! ํ์ ์คํฌ๋ฆฝํธ๋ฅผ ๋ฐฐ์ฐ๊ณ , ํ๋ก์ ํธ์ ์ ์ฉํด๋ณด๊ณ , ์ปค๋ฎค๋ํฐ์ ๊ธฐ์ฌํด๋ด. ๊ทธ๋ฆฌ๊ณ ๋งํ๋ ๋ถ๋ถ์ด ์๋ค๋ฉด ์ฃผ์ ํ์ง ๋ง๊ณ ๋์์ ์์ฒญํด. ํ์ ์คํฌ๋ฆฝํธ ์ปค๋ฎค๋ํฐ๋ ์ ๋ง ์น์ ํ๊ณ ํ๋ฐํ๊ฑฐ๋ . ๐ค
ํ๋ณตํ ํ์ ์คํฌ๋ฆฝํธ ์ฝ๋ฉ ๋๊ธธ ๋ฐ๋ผ! Happy TypeScripting! ๐โจ
๐ ๋ ๋ฐฐ์ฐ๊ณ ์ถ๋ค๋ฉด?
ํ์
์คํฌ๋ฆฝํธ๋ฅผ ๋ ๊น์ด ๋ฐฐ์ฐ๊ณ ์ถ๊ฑฐ๋, ์ค์ ํ๋ก์ ํธ์ ์ ์ฉํ๋ ๋ฐ ๋์์ด ํ์ํ๋ค๋ฉด
์ฌ๋ฅ๋ท์์ ์ ๋ฌธ๊ฐ๋ค์ ๋ฉํ ๋ง๊ณผ ๊ฐ์๋ฅผ ๋ฐ์๋ณด์ธ์!
์ค๋ฌด ๊ฒฝํ์ด ํ๋ถํ ๊ฐ๋ฐ์๋ค์ด ์ฌ๋ฌ๋ถ์ ์ฑ์ฅ์ ๋์๋๋ฆฝ๋๋ค. ๐ช
๊ด๋ จ ํค์๋
๋๊ธ ์์ฑ
์ด ๊ธ์ ๋ํ ์ฌ๋ฌ๋ถ์ ์๊ฐ์ ๋ค๋ ค์ฃผ์ธ์
๋ก๊ทธ์ธ์ด ํ์ํฉ๋๋ค
๋๊ธ์ ์์ฑํ๋ ค๋ฉด ๋จผ์ ๋ก๊ทธ์ธํด์ฃผ์ธ์.
๋๊ธ 0
์ง์์ธ์ ์ฒ - ์ง์ ์ฌ์ฐ๊ถ ๋ณดํธ ๊ณ ์ง
์ง์ ์ฌ์ฐ๊ถ ๋ณดํธ ๊ณ ์ง
- ์ ์๊ถ ๋ฐ ์์ ๊ถ: ๋ณธ ์ปจํ ์ธ ๋ ์ฌ๋ฅ๋ท์ ๋ ์ AI ๊ธฐ์ ๋ก ์์ฑ๋์์ผ๋ฉฐ, ๋ํ๋ฏผ๊ตญ ์ ์๊ถ๋ฒ ๋ฐ ๊ตญ์ ์ ์๊ถ ํ์ฝ์ ์ํด ๋ณดํธ๋ฉ๋๋ค.
- AI ์์ฑ ์ปจํ ์ธ ์ ๋ฒ์ ์ง์: ๋ณธ AI ์์ฑ ์ปจํ ์ธ ๋ ์ฌ๋ฅ๋ท์ ์ง์ ์ฐฝ์๋ฌผ๋ก ์ธ์ ๋๋ฉฐ, ๊ด๋ จ ๋ฒ๊ท์ ๋ฐ๋ผ ์ ์๊ถ ๋ณดํธ๋ฅผ ๋ฐ์ต๋๋ค.
- ์ฌ์ฉ ์ ํ: ์ฌ๋ฅ๋ท์ ๋ช ์์ ์๋ฉด ๋์ ์์ด ๋ณธ ์ปจํ ์ธ ๋ฅผ ๋ณต์ , ์์ , ๋ฐฐํฌ, ๋๋ ์์ ์ ์ผ๋ก ํ์ฉํ๋ ํ์๋ ์๊ฒฉํ ๊ธ์ง๋ฉ๋๋ค.
- ๋ฐ์ดํฐ ์์ง ๊ธ์ง: ๋ณธ ์ปจํ ์ธ ์ ๋ํ ๋ฌด๋จ ์คํฌ๋ํ, ํฌ๋กค๋ง, ๋ฐ ์๋ํ๋ ๋ฐ์ดํฐ ์์ง์ ๋ฒ์ ์ ์ฌ์ ๋์์ด ๋ฉ๋๋ค.
- AI ํ์ต ์ ํ: ์ฌ๋ฅ๋ท์ AI ์์ฑ ์ปจํ ์ธ ๋ฅผ ํ AI ๋ชจ๋ธ ํ์ต์ ๋ฌด๋จ ์ฌ์ฉํ๋ ํ์๋ ๊ธ์ง๋๋ฉฐ, ์ด๋ ์ง์ ์ฌ์ฐ๊ถ ์นจํด๋ก ๊ฐ์ฃผ๋ฉ๋๋ค.
์์ง ๋๊ธ์ด ์์ต๋๋ค.