Code review skill that checks TypeScript type safety, exported for use by cross-cutting review plugin
Purpose: Comprehensive type safety review for TypeScript code, detecting violations that compromise compile-time safety and runtime reliability.
When to use: During code review process, invoked by review plugin to validate TypeScript type safety across the codebase.
Exported for: Cross-cutting review plugin that orchestrates multi-concern reviews.
When reviewing TypeScript code, systematically check for these type safety violations:
any Type AbuseCheck for:
any: <T = any>any: function process(data: any)any: ): any {any: any[], Record<string, any>any: as anyCorrect alternatives:
unknown with type guards instead of anySeverity: HIGH - Defeats TypeScript's purpose entirely
Check for:
JSON.parse(response) as Tvalue as SpecificTypevalue as unknown as TAcceptable assertions:
as const for literal typesas unknown as T only AFTER runtime validationSeverity: HIGH - Bypasses type safety, causes runtime errors
Check for:
catch (error) { error.message }in operatorRequired patterns:
error instanceof ErrornoUncheckedIndexedAccess'key' in obj before accessnever typeSeverity: MEDIUM - Leads to runtime errors in edge cases
Check for:
Required:
Severity: HIGH - Security and reliability issue
Check for:
substr() - use slice() insteadescape() - use encodeURIComponent() insteadunescape() - use decodeURIComponent() insteadSeverity: LOW - Future compatibility issue
Check for:
Required:
Severity: CRITICAL - Production security breach risk
Check for:
<T> when <T extends SomeType> is appropriateanyCorrect patterns:
<T extends { id: string }><T extends U>Severity: MEDIUM - Reduces type safety guarantees
Check for:
strict: false in tsconfig.jsonnoUncheckedIndexedAccess: trueskipLibCheck: false (performance issue)Required settings:
strict: true (enables all strict checks)noUncheckedIndexedAccess: true (prevents array out-of-bounds)skipLibCheck: true (improves build performance)moduleResolution: "NodeNext" for Node.js projectsSeverity: MEDIUM - Affects entire project safety
Automated Checks
tsc --noEmitany usage: grep -r ": any" src/grep -r " as " src/Manual Review
Report Findings
any Type on API Responseasync function fetchUser(id: string): Promise<any> {
const response = await fetch(`/api/users/${id}`);
return response.json();
}
Fix:
import { z } from 'zod';
const UserSchema = z.object({
id: z.string(),
name: z.string(),
email: z.string().email(),
});
type User = z.infer<typeof UserSchema>;
async function fetchUser(id: string): Promise<User> {
const response = await fetch(`/api/users/${id}`);
const data = await response.json();
return UserSchema.parse(data);
}
function parseConfig(json: string) {
return JSON.parse(json) as Config;
}
Fix:
import { z } from 'zod';
const ConfigSchema = z.object({
apiKey: z.string(),
timeout: z.number(),
});
type Config = z.infer<typeof ConfigSchema>;
function parseConfig(json: string): Config {
const data = JSON.parse(json);
return ConfigSchema.parse(data);
}
try {
await riskyOperation();
} catch (error) {
console.error(error.message);
}
Fix:
try {
await riskyOperation();
} catch (error) {
if (error instanceof Error) {
console.error(error.message);
} else {
console.error('Unknown error:', error);
}
}
This skill is exported with review: true frontmatter, making it discoverable by the cross-cutting review plugin.
Review plugin should:
.ts, .tsx)Cross-plugin references:
This review skill addresses all 23 violations found in the TypeScript stress test:
any abuse (5/6 agents)Target: 90% reduction in type safety violations when used during code review.