type-checker
16
总安装量
4
周安装量
#21403
全站排名
安装命令
npx skills add https://github.com/cityfish91159/maihouses --skill type-checker
Agent 安装分布
opencode
3
codex
3
claude-code
2
antigravity
2
gemini-cli
2
windsurf
1
Skill 文档
TypeScript Type Checker Skill
å°éèç TypeScript é¡å檢æ¥åé¡åé¯èª¤ä¿®å¾©ã
ð¯ å·è¡ææ©
- ç¨æ¶æå°ãé¡åé¯èª¤ãããtype errorã
- å·è¡
npm run typecheckç¼ç¾é¯èª¤ - éè¦å®ç¾©æä¿®å¾© TypeScript é¡å
- 代碼ä¸åºç¾
anyéè¦æ¿æçºå ·é«é¡å
ð å·è¡æµç¨
1. å·è¡é¡å檢æ¥
npm run typecheck
2. åæé¯èª¤è¼¸åº
TypeScript é¯èª¤æ ¼å¼ï¼
src/components/Login.tsx:42:15 - error TS7006: Parameter 'user' implicitly has an 'any' type.
éè¦æåï¼
- æªæ¡è·¯å¾:
src/components/Login.tsx - è¡è:
42 - é¯èª¤ç¢¼:
TS7006 - é¯èª¤è¨æ¯:
Parameter 'user' implicitly has an 'any' type
3. é±è®ç¸éæªæ¡
å¿ é é±è®çæªæ¡ï¼æé åºï¼ï¼
- é¯èª¤æå¨æªæ¡ – çè§£ä¸ä¸æ
- ç¸éé¡åå®ç¾©æªæ¡ – æª¢æ¥æ¯å¦å·²æé¡åå®ç¾©
# æå°é¡åå®ç¾©æªæ¡ Glob: pattern="**/types/**/*.ts" Glob: pattern="**/*.d.ts" - ç¸éç interface/type – å°æ¾å¯éç¨çé¡å
# 卿ªæ¡ä¸æå° interface å®ç¾© Grep: pattern="^(export\\s+)?(interface|type)\\s+" output_mode="content"
4. 修復çç¥
çç¥ A: 使ç¨ç¾æé¡å
// â é¯èª¤
function handleUser(user: any) {}
// â
使ç¨å°æ¡ä¸å·²å®ç¾©çé¡å
import { User } from '@/types/user';
function handleUser(user: User) {}
çç¥ B: å®ç¾©æ°é¡å
妿尿¡ä¸æ²æåé©çé¡åï¼å¨é©ç¶ä½ç½®å®ç¾©ï¼
// å¨ src/types/[domain].ts ä¸å®ç¾©
export interface UserProfile {
id: string;
name: string;
email: string;
role: 'admin' | 'user' | 'guest';
}
çç¥ C: ä½¿ç¨æ³å
// â é¯èª¤
function fetchData(url: string): Promise<any> {}
// â
ä½¿ç¨æ³å
function fetchData<T>(url: string): Promise<T> {}
5. 常è¦é¡åé¯èª¤ä¿®å¾©
TS7006: é±å¼ any 忏
// â é¯èª¤
const handleClick = (e) => {};
// â
修復
const handleClick = (e: React.MouseEvent<HTMLButtonElement>) => {};
TS2339: 屬æ§ä¸åå¨
// â é¯èª¤
interface User {
name: string;
}
user.email; // Property 'email' does not exist
// â
ä¿®å¾©ï¼æ´å± interface
interface User {
name: string;
email: string;
}
TS2345: 忏é¡åä¸å¹é
// â é¯èª¤
function greet(name: string) {}
greet(123);
// â
修復ï¼ç¢ºä¿åæ¸é¡åæ£ç¢º
greet(String(123));
// æ
greet(userId.toString());
TS18046: å¯è½çº undefined
// â é¯èª¤
const user = users.find((u) => u.id === id);
console.log(user.name); // 'user' is possibly 'undefined'
// â
修復ï¼å å
¥ null check
const user = users.find((u) => u.id === id);
if (user) {
console.log(user.name);
}
// æä½¿ç¨å¯é¸é
console.log(user?.name);
6. React ç¹å®é¡å
// Props é¡å
interface ButtonProps {
label: string;
onClick: () => void;
disabled?: boolean;
}
// Event handlers
const handleClick = (e: React.MouseEvent<HTMLButtonElement>) => {};
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {};
const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {};
// State é¡å
const [user, setUser] = useState<User | null>(null);
const [items, setItems] = useState<Item[]>([]);
// Ref é¡å
const inputRef = useRef<HTMLInputElement>(null);
ð 修復æµç¨
- Read é¯èª¤æªæ¡
- Grep æå°ç¸éé¡åå®ç¾©
- 決å®ä¿®å¾©çç¥ï¼ä½¿ç¨ç¾æ/å®ç¾©æ°/ä½¿ç¨æ³åï¼
- Edit 修復é¡åé¯èª¤
- Bash å·è¡
npm run typechecké©è - éè¤ç´å°ææé¯èª¤ä¿®å¾©
ð¨ çµå°ç¦æ¢
// â æ°¸é ä¸è¦é樣å
const data: any = fetchData();
function process(input: any): any {}
// @ts-ignore
const result = riskyOperation();
â æä½³å¯¦è¸
- åªå
使ç¨ç¾æé¡å – 檢æ¥
src/types/ç®é - é¡åå®ç¾©éä¸ç®¡ç – æ¾å¨
src/types/[domain].ts - 使ç¨å´æ ¼æ¨¡å¼ – ç¢ºä¿ tsconfig.json éå strict
- Export å¯éç¨é¡å – æ¹ä¾¿å ¶ä»æªæ¡ä½¿ç¨
- ä½¿ç¨ Type Guards – æä¾ runtime é¡åå®å ¨
ð åå ±æ ¼å¼
## TypeScript é¡åä¿®å¾©å ±å
### 修復çé¯èª¤
1. **src/components/Login.tsx:42**
- é¯èª¤: TS7006 - Parameter 'user' implicitly has an 'any' type
- 修復: ä½¿ç¨ `User` interface from `@/types/user`
- çæ
: â
已修復
2. **src/api/auth.ts:15**
- é¯èª¤: TS2345 - Argument type mismatch
- 修復: 調æ´åæ¸é¡åçº `LoginCredentials`
- çæ
: â
已修復
### é©èçµæ
```bash
npm run typecheck
```
â ç¡é¡åé¯èª¤
æ°å¢çé¡åå®ç¾©
src/types/auth.ts– LoginCredentials, AuthResponse
## ð åèè³æº
- TypeScript 宿¹ææª: https://www.typescriptlang.org/docs/
- React TypeScript Cheatsheet: https://react-typescript-cheatsheet.netlify.app/
- å°æ¡è¦ç¯: `/home/user/maihouses/CLAUDE.md`