← Back to list
Why

typescript-type-safety
by ffMathy
My digital assistant that runs the house.
⭐ 2🍴 0📅 Jan 24, 2026
SKILL.md
name: typescript-type-safety description: TypeScript type safety guidelines. Use this when writing TypeScript code, especially when handling errors or unknown data types.
TypeScript Type Safety
CRITICAL: Never use any type - it defeats TypeScript's purpose.
Rules
- Use proper types for all data structures
- Use
unknownfor truly unknown data, then narrow with type guards - Use type assertions sparingly and only when verified
- Enable strict mode in tsconfig.json
Error Handling
❌ BAD - Using any:
server.on('error', (error: any) => {
console.error('Server error:', error.message);
if (error.details) {
console.error('Details:', error.details.message);
}
});
✅ GOOD - Proper Type Assertion:
server.on('error', (error) => {
const typedError = error as Error & {
details?: { message?: string };
};
console.error('Server error:', typedError.message);
if (typedError.details?.message) {
console.error('Details:', typedError.details.message);
}
});
✅ EVEN BETTER - Type Guard:
function isErrorWithDetails(error: unknown): error is Error & { details: { message: string } } {
return error instanceof Error &&
typeof (error as any).details === 'object' &&
typeof (error as any).details.message === 'string';
}
server.on('error', (error) => {
console.error('Server error:', error instanceof Error ? error.message : String(error));
if (isErrorWithDetails(error)) {
console.error('Details:', error.details.message);
}
});
Why any is Problematic
- Disables all TypeScript checking
- No autocomplete in IDE
- Typos caught only at runtime
- Makes refactoring dangerous
- Defeats the purpose of TypeScript
When to Use Type Assertions
- Only after verifying the shape/type at runtime
- When TypeScript can't infer but you know the type
- Use
asassertions, not angle brackets - Document why the assertion is safe
Score
Total Score
60/100
Based on repository quality metrics
✓SKILL.md
SKILL.mdファイルが含まれている
+20
✓LICENSE
ライセンスが設定されている
+10
○説明文
100文字以上の説明がある
0/10
○人気
GitHub Stars 100以上
0/15
○最近の活動
3ヶ月以内に更新がある
0/10
○フォーク
10回以上フォークされている
0/5
✓Issue管理
オープンIssueが50未満
+5
✓言語
プログラミング言語が設定されている
+5
○タグ
1つ以上のタグが設定されている
0/5
Reviews
💬
Reviews coming soon