用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/G1Joshi/Agent-Skills --skill typescript命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
正在显示 SKILL.md
基于 SOC 职业分类
| name | typescript |
| description | TypeScript static typing with interfaces, generics, decorators, and type inference. Use for .ts files. |
Static typing for JavaScript with advanced type features for safer, more maintainable code.
.ts or .tsx files// Define a typed interface
interface User {
id: string;
name: string;
email: string;
createdAt: Date;
}
// Type-safe function
async function fetchUser(id: string): Promise<User | undefined> {
const response = await fetch(`/api/users/${id}`);
return response.ok ? response.json() : undefined;
}
// Interface for object shapes (extendable)
interface User {
id: string;
name: string;
email: string;
}
// Type for unions, intersections, mapped types
type Status = "pending" | "active" | "inactive";
type UserWithStatus = User & { status: Status };
// Generic functions
function first<T>(items: T[]): T | undefined {
return items[0];
}
// Generic constraints
function getProperty<T, K extends keyof T>(obj: T, key: K): T[K] {
return obj[key];
}
// Generic interfaces
interface Repository<T extends { id: string }> {
findById(id: string): Promise<T | null>;
save(entity: T): Promise<T>;
delete(id: string): Promise<void>;
}
Problem: Narrowing unknown types at runtime.
Solution:
// Type predicates
function isUser(value: unknown): value is User {
return (
typeof value === "object" &&
value !== null &&
"id" in value &&
"name" in value
);
}
// Discriminated unions
type Result<T> = { success: true; data: T } | { success: false; error: string };
function handleResult<T>(result: Result<T>) {
if (result.success) {
console.log(result.data); // Type: T
} else {
console.error(result.error); // Type: string
}
}
// Make all properties optional
type Partial<T> = { [P in keyof T]?: T[P] };
// Pick specific properties
type UserPreview = Pick<User, "id" | "name">;
// Omit specific properties
type UserCreate = Omit<User, "id" | "createdAt">;
// Brand types for nominal typing
type UserId = string & { readonly brand: unique symbol };
Do:
strict mode in tsconfig.jsonunknown instead of any for truly unknown typesDon't:
any to bypass type checkingas) when narrowing works// @ts-ignoreinterface and type inconsistently| Error | Cause | Solution |
|---|---|---|
Type 'X' is not assignable to type 'Y' | Type mismatch | Check types, use type guards |
Object is possibly undefined | Nullable value access | Use optional chaining or narrowing |
Cannot find module | Missing type declarations | Install @types/package |