check_type_compatibility
Verify TypeScript type compatibility by checking if a source type can be assigned to a target type, ensuring type safety in your code.
Instructions
Check if two types are compatible/assignable
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sourceType | Yes | The source type | |
| targetType | Yes | The target type |
Implementation Reference
- src/mcp-server.ts:360-375 (handler)Handler function in MCPServer that executes the check_type_compatibility tool by calling TypeValidator and formatting the response.private async handleCheckTypeCompatibility(sourceType: string, targetType: string) { const result = this.typeValidator.checkTypeCompatibility(sourceType, targetType); return { content: [ { type: "text", text: JSON.stringify({ sourceType, targetType, ...result }, null, 2) } ] }; }
- src/type-validator.ts:164-199 (handler)Core implementation of the type compatibility check using a test assignment compiled with TypeScript compiler API to detect assignability errors.checkTypeCompatibility(sourceType: string, targetType: string): ValidationResult { const errors: ValidationError[] = []; const warnings: ValidationWarning[] = []; try { // Create a test assignment to check compatibility const testCode = ` let source: ${sourceType}; let target: ${targetType}; target = source; // This will fail if types are incompatible `; const result = this.validateTypeUsage(testCode); // Filter out assignment-specific errors and focus on type compatibility const compatibilityErrors = result.errors.filter(error => error.message.includes("not assignable") || error.message.includes("incompatible") ); errors.push(...compatibilityErrors); warnings.push(...result.warnings); } catch (error) { errors.push({ message: `Type compatibility check failed: ${error instanceof Error ? error.message : String(error)}`, code: "COMPATIBILITY_ERROR" }); } return { valid: errors.length === 0, errors, warnings }; }
- src/mcp-server.ts:162-179 (registration)Registration of the check_type_compatibility tool in the ListTools response, including name, description, and input schema.{ name: "check_type_compatibility", description: "Check if two types are compatible/assignable", inputSchema: { type: "object", properties: { sourceType: { type: "string", description: "The source type" }, targetType: { type: "string", description: "The target type" } }, required: ["sourceType", "targetType"] } },
- src/mcp-server.ts:25-27 (schema)TypeScript interface definition for tool arguments used for type-safe validation.check_type_compatibility: { sourceType: string; targetType: string }; reinitialize_indexer: { workingDir?: string }; }
- src/mcp-server.ts:241-247 (handler)Switch case dispatcher in CallToolRequestHandler that validates arguments and invokes the tool handler.case "check_type_compatibility": { const compatArgs = this.validateArgs<ToolArguments["check_type_compatibility"]>(args); return await this.handleCheckTypeCompatibility( compatArgs.sourceType, compatArgs.targetType ); }