Manusで任意のスキルを実行
ワンクリックで
ワンクリックで
ワンクリックでManusで任意のスキルを実行
始めるtype-validator
スター322
フォーク91
更新日2026年4月19日 13:39
TypeScript严格模式检查
インストール
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
SKILL.md
readonlyメニュー
TypeScript严格模式检查
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
SOC 職業分類に基づく
提交、推送并创建 PR
自动发现项目中的代码问题并提交 GitHub Issue
安全审计技能,用于检查和修复依赖安全问题
文档自动生成
CI检查验证和质量保障
生成代码评审友好的 commit 信息
| name | type-validator |
| description | TypeScript严格模式检查 |
我是 TypeScript 严格模式检查技能,专门针对 xiaozhi-client 项目的 TypeScript 配置进行类型安全检查和修复建议,同时遵循务实开发理念。
核心能力:检测并修复所有 any 类型的使用,符合项目的严格类型要求。
const/let/var 声明的 any 类型// ❌ 原始代码
function process(data: any): any {
return data.value;
}
// ✅ 修复后(xiaozhi-client 项目标准)
function process<T extends Record<string, unknown>>(data: T): T[keyof T] {
return data.value as T[keyof T];
}
// MCP 相关的修复示例
// ❌ 原始代码
function handleMCPMessage(message: any): any {
return { id: message.id, result: "processed" };
}
// ✅ 修复后
function handleMCPMessage(message: MCPRequest): MCPResponse {
return {
jsonrpc: "2.0",
id: message.id,
result: "processed"
};
}
确保所有接口、类型定义和函数都有完整的类型注解。
? 标记可选属性// 不完整的类型定义
interface User {
name: string;
// age 类型缺失
address?: any; // 使用 any 类型
}
// 完整的类型定义
interface User {
name: string;
age: number;
address?: {
street: string;
city: string;
zipCode: string;
};
}
确保运行时验证与 TypeScript 类型定义的一致性。
z.infer 类型使用import { z } from "zod";
// TypeScript 接口
interface LightControlParams {
name: string;
action: "turn_on" | "turn_off";
brightness?: number;
}
// Zod 验证 Schema
const lightControlSchema = z.object({
name: z.string(),
action: z.enum(["turn_on", "turn_off"]),
brightness: z.number().min(1).max(100).optional(),
});
// 类型推断确保一致性
type LightControlParams = z.infer<typeof lightControlSchema>;
确保 xiaozhi-client 项目复杂路径别名系统的类型安全,避免别名使用导致的类型错误。
// 检查别名导入的类型定义(xiaozhi-client 项目 @/ 路径别名体系)
import { MCPConnection } from "@/mcp-core";
import { Container } from "@/cli";
import { StartCommand } from "@/cli/commands/start";
import { HandlerManager } from "@/server/handlers/HandlerManager";
import type { XiaozhiConfig, AppConfig } from "@/types";
// 验证导入的模块是否具有正确的类型定义
// 确保所有 @/ 别名指向 src/ 下的正确文件
// 确保 xiaozhi-client 项目 @/ 路径别名映射不会导致类型冲突
interface XiaozhiClientTypeMapping {
"@/types": "./src/types"; // 共享类型定义
"@/config": "./src/config"; // 配置管理
"@/mcp-core": "./src/mcp-core"; // MCP 协议核心
"@/endpoint": "./src/endpoint"; // 端点处理
"@/esp32": "./src/esp32"; // ESP32 硬件相关
"@/cli": "./src/cli"; // CLI 命令行工具
"@/utils": "./src/utils"; // 通用工具
"@/server": "./src/server"; // 后端服务
}
// 验证映射的正确性和类型完整性
与现有的 Biome 代码检查工具集成,确保类型检查与代码规范的一致性。
// 代码前
function processData(data: any): any {
return JSON.parse(data);
}
// 代码后
function processData(data: unknown): unknown {
if (typeof data === 'string') {
return JSON.parse(data);
}
throw new Error('Invalid data type');
}
// 代码前
function setValue(value: any) {
// ...
}
// 代码后
function setValue(value: string | number | boolean) {
// ...
}
// 代码前
function createResponse(data: any, status: any) {
return { data, status };
}
// 代码后
function createResponse<T, U extends number>(data: T, status: U) {
return { data, status };
}
function isString(value: unknown): value is string {
return typeof value === 'string';
}
function isNumber(value: unknown): value is number {
return typeof value === 'number' && !isNaN(value);
}
function isArray(value: unknown): value is unknown[] {
return Array.isArray(value);
}
function isMCPRequest(value: unknown): value is MCPRequest {
return (
typeof value === 'object' &&
value !== null &&
'jsonrpc' in value &&
(value as any).jsonrpc === '2.0' &&
'id' in value &&
'method' in value
);
}
function isXiaozhiConfig(value: unknown): value is XiaozhiConfig {
return (
typeof value === 'object' &&
value !== null &&
('mcpEndpoint' in value || 'mcpServers' in value)
);
}
function isTransportAdapter(value: unknown): value is TransportAdapter {
return (
typeof value === 'object' &&
value !== null &&
'connect' in value &&
'disconnect' in value &&
'send' in value
);
}
export class ValidationError extends Error {
public readonly code: string;
public readonly field?: string;
constructor(message: string, code: string, field?: string) {
super(message);
this.name = 'ValidationError';
this.code = code;
if (field !== undefined) {
this.field = field;
}
}
}
type Result<T, E = Error> =
| { success: true; data: T }
| { success: false; error: E };
function safeParse<T>(data: unknown, schema: z.Schema<T>): Result<T> {
try {
const result = schema.parse(data);
return { success: true, data: result };
} catch (error) {
if (error instanceof z.ZodError) {
return { success: false, error: new ValidationError(error.message, 'VALIDATION_ERROR') };
}
return { success: false, error: error as Error };
}
}
interface TypeIssue {
type: 'any_usage' | 'missing_type' | 'invalid_cast' | 'unsafe_assignment';
severity: 'error' | 'warning' | 'info';
file: string;
line: number;
column: number;
message: string;
suggestion: string;
}
const issues: TypeIssue[] = scanTypeIssues(sourceCode);
interface TypeAnalysis {
anyUsageCount: number;
missingTypes: string[];
invalidCasts: Array<{ from: string; to: string; line: number }>;
unsafeAssignments: Array<{ variable: string; type: string; line: number }>;
recommendations: string[];
}
const analysis = analyzeTypeIssues(issues);
interface FixResult {
fixedIssues: number;
remainingIssues: TypeIssue[];
modifiedFiles: string[];
warnings: string[];
}
const result = applyTypeFixes(analysis, options);
// 自动替换规则
const replacementRules = [
{
pattern: /const\s+(\w+)\s*:\s*any\s*=/,
replacement: (match, varName) => `const ${varName}: unknown =`
},
{
pattern: /function\s+(\w+)\s*\([^)]*\)\s*:\s*any\s*{/,
replacement: (match, fnName) => `function ${fnName}(): unknown {`
}
];
// 自动添加类型注解
function inferAndAddTypes(ast: ASTNode): TypeAnnotation[] {
// 基于 AST 分析推断类型
// 生成适当的类型注解
}
// 自动整理和优化类型导入
function organizeTypeImports(sourceFile: SourceFile): void {
// 确保所有必要的类型都已导入
// 移除未使用的类型导入
// 按照项目规范排序导入语句
}
# 运行类型检查(xiaozhi-client 项目)
pnpm typecheck
# 运行代码规范和格式检查
pnpm lint
# 运行拼写检查
pnpm spellcheck
# 运行所有质量检查
pnpm check:all
# 运行测试并检查覆盖率
pnpm test:coverage
// 确保类型检查不影响运行时性能
function performanceCheck() {
const start = performance.now();
// 类型检查逻辑
const end = performance.now();
console.log(`Type validation took ${end - start} milliseconds`);
}
# 检查整个项目
npx type-validator check
# 检查特定文件
npx type-validator check src/services/light.ts
# 自动修复
npx type-validator fix --auto
# 生成报告
npx type-validator report --format json --output type-report.json
# GitHub Actions 示例
- name: Type Validation
run: |
npx type-validator check --strict
npx type-validator report --format junit --output type-results.xml
通过这个技能,可以确保 xiaozhi-client 项目始终保持高质量的 TypeScript 代码标准,减少运行时错误,提升开发效率。特别针对 MCP 协议的复杂类型和项目的路径别名系统提供专门的类型安全保障。