init: common-skills v1

This commit is contained in:
Team
2026-03-26 21:00:51 +08:00
commit 264dacf157
16 changed files with 859 additions and 0 deletions
+47
View File
@@ -0,0 +1,47 @@
---
name: typescript-skill
description: TypeScript coding patterns and type safety guide. Use when writing, reviewing, or debugging TypeScript code.
---
# TypeScript Skill
## Key Rules
### Always Prefer Explicit Types
```typescript
// Bad
const process = (data: any) => data.value;
// Good
interface GameState { value: number; }
const process = (data: GameState): number => data.value;
```
### Use `unknown` Instead of `any`
```typescript
// Bad
function parse(input: any) { return input.name; }
// Good
function parse(input: unknown): string {
if (typeof input === 'object' && input !== null && 'name' in input) {
return String((input as { name: unknown }).name);
}
throw new Error('Invalid input');
}
```
### Prefer `const` Assertions for Literals
```typescript
const DIRECTIONS = ['up', 'down', 'left', 'right'] as const;
type Direction = typeof DIRECTIONS[number]; // 'up' | 'down' | 'left' | 'right'
```
## Common Patterns
| Pattern | Use Case |
|---------|----------|
| `type` | Unions, intersections, primitives |
| `interface` | Object shapes (extendable) |
| `enum` | Named constants (prefer `as const` for simple cases) |
| `generic <T>` | Reusable, type-safe utilities |
+20
View File
@@ -0,0 +1,20 @@
{
"skill_name": "typescript",
"evals": [
{
"id": 1,
"prompt": "How do I avoid using 'any' type in TypeScript?",
"expected_output": "Explains using 'unknown' instead of 'any', with type guards, and shows interface/type definitions as alternatives."
},
{
"id": 2,
"prompt": "Show me how to create a type-safe function in TypeScript that processes a list of items",
"expected_output": "Demonstrates a generic function with <T> type parameter, proper return type annotation, and no use of 'any'."
},
{
"id": 3,
"prompt": "What's the difference between type and interface in TypeScript?",
"expected_output": "Explains that interfaces are extendable and better for object shapes, types support unions/intersections, with concrete examples of each."
}
]
}