typescript
npx skills add https://github.com/dalestudy/skills --skill typescript
Agent 安装分布
Skill 文档
TypeScript
TypeScript í¸ëë¶ ê¸°ë° íì ì ì ë° ë² ì¤í¸ íëí°ì¤. 기본 문ë²Â·íì ì¡°ì·ì í¸ë¦¬í° íì ìì¸ë references/ ë° Handbook ì°¸ê³ .
기본 ìì¹
1. íì ì¶ë¡ íì©
ë¶íìí ì´ë ¸í ì´ì ìëµ. ë³ê²½ ì ì´ì¤ ìì ë¶ë´ ê°ì, ì¶ë¡ ì´ ë ì íí ê²½ì° ë§ì.
// â
const name: string = "John";
const user: { name: string; age: number } = { name: "John", age: 30 };
// â
const name = "John";
const user = { name: "John", age: 30 };
2. ëª ìì ë°í íì
í¨ì ê³ì½ ëª íí, ë°í íì ì¤ë³ê²½ ë°©ì§. ê³µê° API·복ì¡í ë¡ì§ìì íì.
function calculateTotal(items: Item[]): number {
return items.reduce((sum, item) => sum + item.price, 0);
}
async function fetchUser(id: string): Promise<User> {
const res = await fetch(`/api/users/${id}`);
return res.json();
}
3. any ì¬ì© ê¸ì§
íì
ìì ì±Â·ìëìì± ë¬´í¨í. unknown + íì
ê°ë ëë 구체 íì
ì¬ì©.
// â
function process(data: any) {
return data.value;
}
// â
function process(data: unknown): number {
if (typeof data === "object" && data !== null && "value" in data)
return (data as { value: number }).value;
throw new Error("Invalid data");
}
í¨ì · ì ë¤ë¦
- í¨ì: ì¸ì·ë°í íì ëª ì. ì¤ë²ë¡ë ì 구í ìê·¸ëì²ë ì ëì¨ì¼ë¡.
- ì ë¤ë¦:
T,K extends keyof Të± ì ì½ ëª ì.getProperty<T, K extends keyof T>(obj: T, key: K): T[K]í¨í´ íì©.
íì ê°ë
typeof,instanceof,inì¼ë¡ ë¶ê¸° í íì ì¢í기- ë³µì¡í ê²ì¬ë ì¬ì©ì ì ì ê°ë
(value): value is Tì¬ì©
í í릿:
assets/types.guards.ts
tsconfig
- íë¡ì í¸ ì±ê²©ì ë§ë tsconfig를 ì¬ì©
- íì ìì ì±ì í´ì¹ì§ ìë ì ììë§ ìµì ì ì¡°ì
- ì±/ìë²/ë¼ì´ë¸ë¬ë¦¬ë ì¤ì íì¼ì ë¶ë¦¬
- íì ìë¬ íí¼ ëª©ì ì ìµì ìí ê¸ì§
í í릿:
assets/tsconfig.nextjs.tsassets/tsconfig.node.tsassets/tsconfig.react.ts
ì´ë²¤í¸ íì
- DOM / React ì´ë²¤í¸ë ë´ì¥ íì ì¬ì©
- 커ì¤í ì´ë²¤í¸ë§ ë³ë íì ì ì
- ì´ë²¤í¸ ì¬ì ì ê¸ì§
í í릿:
assets/types.events.ts
ì í¸ë¦¬í° íì
- TypeScript ë´ì¥ ì í¸ë¦¬í° íì ì ê·¸ëë¡ ì¬ì©
- 커ì¤í ì í¸ë¦¬í° íì ë§ ì ì
í í릿:
assets/types.utils.ts
ì¤ì í¨í´
- interface ì°ì : ê°ì²´ ê³ì½Â·íì¥ì
interface, ì ëì¨/ì¸í°ì¹ì ìtype. API ì¤ëª ì ëª ì¬íì¼ë¡ ìì± (/** ë¹íì±í ìí */). as const: 리í°ë´Â·ê°ì²´ ë¶ë³ ë³´ì¡´.typeof obj[keyof typeof obj]ë¡ ì´ëì²ë¼ íì©.- ë¸ëë íì
:
type UserId = string & { readonly brand: unique symbol }ë¡ ëì¼ ìì íì 구ë¶. - íì
ë¨ì¸ ìµìí:
asëì íì ê°ë. - ì ë¤ë¦ ì ì½:
T extends objectë± ëª ì.
íì ìë¬ í´ê²°
| ìë¬ | ëì |
|---|---|
Type 'X' is not assignable to type 'Y' |
íì ê°ëë¡ ë¶ê¸° í í ë¹ |
Property 'X' does not exist on type 'Y' |
íì
íì¥ ëë optional |
Object is possibly 'null' or 'undefined' |
if (x == null) / ?. / ?? |
Argument of type 'X' is not assignable to parameter of type 'Y' |
ì ë¤ë¦ T[] ëë ì¤ë²ë¡ë |
Type 'X' cannot be used as an index type |
keyof typeof obj ì¬ì© |
ëë²ê¹
: í¸ë²ë¡ ì¶ë¡ íì¸, ê°ë·ì ë¤ë¦Â·ì í¸ë¦¬í° íì
ì¼ë¡ í´ê²° í asë ìµí ìë¨.
ì°¸ê³
ì´ ë¬¸ìë¤ì ê·ì¹ì´ ìëë¼ ì°¸ê³ ì©, íë¨ ê¸°ì¤ì ê° skill 문ì를 ì°ì
- TypeScript Handbook – TypeScript ê³µì ê°ë ·íì ìì¤í ë í¼ë°ì¤
- Playground – íì ëì ì¤í ë° ìì ê²ì¦ì©