본문으로 건너뛰기
Skillpedia
일반 코딩15k · #11002

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가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/cursor/plugins/blob/main/harness/pstack/claude-code/skills/typescript-best-practices/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

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.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬