← スキル一覧に戻る
Bad: Using
When You Think You Need

typescript
by HardlyDifficult
Cursor commands and Agent Skills
⭐ 0🍴 0📅 2026年1月23日
SKILL.md
name: typescript description: Use when writing or reviewing TypeScript code, or when the user mentions TypeScript, strict typing, type errors, or type safety.
TypeScript: Strict Typing and Readability
Guidelines for writing maintainable, well-typed TypeScript code.
Core Principles
- Avoid
anyandunknown— Use precise, explicit types at all times - Never silence type errors — Don't use broad assertions like
as anyjust to "make it work" - Optimize for maintainability — Prefer clear, easy-to-read code over clever type gymnastics
- Fail fast — Validate inputs and fail immediately on invalid data rather than using placeholders
Type Safety Rules
Bad: Using any or unknown
function processData(data: any) {
return data.someProperty;
}
const result = apiCall() as any;
Good: Using explicit types
interface DataStructure {
someProperty: string;
otherProperty: number;
}
function processData(data: DataStructure): string {
return data.someProperty;
}
interface ApiResponse {
status: number;
data: DataStructure;
}
const result: ApiResponse = await apiCall();
When You Think You Need any/unknown
Investigate and fix the root cause instead:
| Problem | Solution |
|---|---|
| Upstream types missing/incorrect | Add or fix them |
| Invalid usage or design | Correct the code |
| Third-party types wrong | Augment types or contribute a fix |
Last resort only: Use any/unknown when avoiding them requires disproportionate, complex typings. Keep usage minimal and well-reasoned.
Type Assertions
Bad: Broad type assertions
const value = (someFunction() as any).property;
const data = response as unknown as MyType;
Good: Type guards and validation
function isMyType(value: unknown): value is MyType {
return (
typeof value === 'object' &&
value !== null &&
'expectedProperty' in value
);
}
const data = someFunction();
if (isMyType(data)) {
// Now data is typed as MyType
console.log(data.expectedProperty);
} else {
throw new Error('Invalid data structure');
}
Generic Types
Bad: Untyped generics
function transform(items: any[]) {
return items.map(item => item.value);
}
Good: Typed generics
interface HasValue<T> {
value: T;
}
function transform<T>(items: HasValue<T>[]): T[] {
return items.map(item => item.value);
}
Error Handling
Bad: Catching without typing
try {
await someOperation();
} catch (error) {
console.log(error.message); // error is any
}
Good: Typed error handling
try {
await someOperation();
} catch (error) {
if (error instanceof Error) {
console.log(error.message);
} else {
console.log('Unknown error occurred');
}
}
When Blocked
If you're blocked from fixing the root cause of a type issue:
- Stop and document why you can't fix it properly
- Ask for guidance rather than using
as any
Verification
After making TypeScript changes, always:
- Run
tsc --noEmitto check for type errors - Fix any type errors before considering the work complete
- Ensure all type assertions are justified and minimal
スコア
総合スコア
50/100
リポジトリの品質指標に基づく評価
✓SKILL.md
SKILL.mdファイルが含まれている
+20
○LICENSE
ライセンスが設定されている
0/10
○説明文
100文字以上の説明がある
0/10
○人気
GitHub Stars 100以上
0/15
○最近の活動
3ヶ月以内に更新がある
0/10
○フォーク
10回以上フォークされている
0/5
✓Issue管理
オープンIssueが50未満
+5
✓言語
プログラミング言語が設定されている
+5
○タグ
1つ以上のタグが設定されている
0/5
レビュー
💬
レビュー機能は近日公開予定です