typescript-best-practices
하는 일
스킬은 신뢰할 수 있는 TypeScript 코드를 쓰는 규칙을 제공합니다. 타입 오류와 숨은 충돌을 줄이고 싶은 개발자를 위한 스킬입니다.
사용하는 경우
- ✓에이전트에게 TypeScript나 TSX 파일을 작성하거나 수정하도록 요청할 때.
- ✓코드에서 안전하지 않은 타입 캐스트나 느슨한 타입을 없애고 싶을 때.
- ✓코드가 신뢰하기 전에 외부 데이터를 검사받고 싶은 경우.
스킬 링크
https://github.com/cursor/plugins/blob/main/harness/pstack/claude-code/skills/typescript-best-practices/SKILL.md복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.
사용 방법
가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.
바로 붙여넣을 수 있는 메시지
Claude Code, Codex, Cursor용입니다. 프로젝트 폴더에서 실행하면 스킬이 설치됩니다.
SKILL.md를 다운로드해 에이전트의 스킬 폴더에 넣으세요.
AI에게 요청하는 예시
“이 TypeScript 파일의 타입을 정리해서, 안전하지 않은 캐스트에 기대지 않도록 해 주세요.”
매주 새 스킬 5개. 읽는 데 1분.
작동 방식
에이전트는 태그가 붙은 유니온 타입 사용, 외부 데이터에 unknown 사용, 타입을 믿기 전에 스키마로 데이터를 검사하는 등의 규칙을 따릅니다. 이 규칙은 코드에 불가능한 상태가 들어오지 않도록 막습니다.
기술 내용 (원본 SKILL.md)
작성자의 영어 원문을 GitHub에서 그대로 가져왔습니다.
TypeScript best practices
Apply the type-system-discipline principle skill first.
| Rule | Summary |
|---|---|
| Discriminated unions | Model variants with a kind literal discriminant so impossible states can't be represented. No optional-field bags. |
| Branded types | Brand primitives with & { readonly __brand: "X" } so they can't be mixed up. Validate once at the boundary. A brand comes from a verifying type guard (input is AgentId), never from as. |
| Constructive modeling | Build the shape so the illegal value can't be constructed. [T, ...T[]] for non-empty, [T, T][] for even length, start plus duration for a range. Not a runtime guard, not a wish for refinement types. |
| Simplest total type | Keep T[] while every operation on it stays total. Strengthen to NonEmpty<T> only where the loose type forces !, a cast, or a "should never happen" throw. |
unknown over any |
External data is unknown. |
| Schemas before guards | Before hand-writing a property-by-property type guard, use the repository's runtime schema library and infer the type from the schema, such as z.infer. |
No as casts |
Every as is a runtime crash waiting. Cast only after validation. |
| Narrowing hierarchy | Discriminant switch > in operator > typeof/instanceof > user-defined type guard > as. |
| Type guards | Must verify the claim. A lying guard is worse than as because the bug hides behind a name that says it's safe. Name them isX or hasX. |
| Exhaustiveness | Inline const _exhaustive: never = x; in default arms so the compiler errors when a new variant is added. |
satisfies over as |
Validates the value without widening literal types. |
| Boundary validation | Parse where data crosses in, into a named domain type. Record<string, unknown> (however spelled) stops at that parse. Trust types inside. See the boundary-discipline principle skill. |
| Schema-derived types | Reach for Pick/Omit/Parameters/ReturnType/Awaited/typeof before declaring a new interface. |
| Object args | Pass objects, not positional, so argument order is self-documenting. Skip on hot paths (per-frame render, tokenizers, parsers). |
| Real tests | Don't mock what you can run. Prefer the framework's real test primitives with leak/disposable checks, and verify UI in a running build. Mock only what you can't run locally. |
| Structured telemetry | Prefer structured logger diagnostics with enough context to debug from an id. No console.log in shipped code. |
Examples: references/patterns.md.
자주 묻는 질문
일반 JavaScript 파일에도 맞나요?
이 규칙은 TypeScript 파일, 즉 .ts와 .tsx를 위한 것입니다.
브랜디드 타입이란 무엇인가요?
ID 같은 값에 표시를 붙여, 다른 값과 혼동되지 않게 하는 타입입니다.
as 캐스트를 왜 피하나요?
캐스트는 값을 확인하지 않고 믿으라고 컴파일러에 지시하므로, 실행 중에 실패할 수 있습니다.
상세 정보
작성자의 원본 설명
TypeScript best practices. Use when reading or editing any .ts or .tsx file.
repo: cursor/plugins
인기도
- GitHub 스타
- 15k
- 순위
- #11002
- 라이선스
- —
- 업데이트
- 2026. 10. 31.
댓글
- …
이 저장소의 다른 스킬
advisor
15k사용자가 켜 두면, 큰 결정 전이나 오류에 막혔을 때처럼 핵심 시점에 에이전트가 더 강력한 두 번째 모델에게 자문을 구하도록 합니다.
check-agent-compatibility
15kAI 코딩 에이전트가 저장소를 시작하고, 검증하고, 문서화할 수 있는지 전체 점검해, 하나의 호환성 점수와 주요 문제를 돌려줍니다.
cli-for-agents
15kAI 에이전트가 프롬프트 없이 실행할 수 있도록 명령줄 도구를 설계하거나 검토하며, 명확한 도움말과 예시를 담도록 에이전트를 가르칩니다.
continual-learning
15k과거 채팅을 검토하는 일을 전담 메모리 업데이터에게 맡겨서 AGENTS.md 메모를 최신 상태로 유지합니다.