3.5 KiB
3.5 KiB
TypeScript Fixes - Quick Reference
Error Code Cheat Sheet
| Error Code | Meaning | Fix Pattern |
|---|---|---|
| TS2307 | Cannot find module | Add missing import |
| TS2304 | Cannot find name | Add missing import or type |
| TS7030 | Not all code paths return | Add return statement |
| TS2322 | Type not assignable | Add type cast or fix type |
| TS2339 | Property does not exist | Add type assertion or include relation |
| TS2352 | Conversion may be mistake | Add as unknown as TargetType |
| TS2353 | Property does not exist in type | Check Prisma schema or use correct field |
| TS18046 | Property is of type 'unknown' | Add type assertion |
| TS2571 | Object is of type 'unknown' | Add type assertion |
| TS18047 | Possibly 'null' | Add null check or ! assertion |
| TS2345 | Argument type mismatch | Fix parameter type or cast |
| TS2551 | Property does not exist on PrismaClient | Check schema, use correct model name |
| TS2365 | Operator cannot be applied | Use Decimal methods instead of operators |
| TS2531 | Object is possibly 'null' | Add null check |
| TS2698 | Spread types error | Fix object type before spreading |
Common Fix Patterns
1. Missing Import
// Error: Cannot find name 'uuidv4'
import { v4 as uuidv4 } from 'uuid';
2. Missing Return
// Error: Not all code paths return
catch (error) {
return next(error); // Add 'return'
}
3. JsonValue Cast
// Error: Type 'Record<string, unknown>' is not assignable
metadata: data as Prisma.InputJsonValue
4. Type Conversion via Unknown
// Error: Conversion may be mistake
metadata: request as unknown as Record<string, unknown>
5. Unknown Type Assertion
// Error: Property is of type 'unknown'
const data = consolidatedData as Record<string, unknown>;
const bankDetails = data.bankDetails as BankDetails;
6. Null Safety
// Error: Possibly 'null'
if (value) {
// Use value
}
// Or
const result = value!.property;
7. Prisma Property Access
// Error: Property does not exist
// Solution 1: Include relation
const bond = await prisma.gruBond.findUnique({
where: { bondId },
include: { bondDetails: true }
});
// Solution 2: Type assertion
const bondName = (bond as any).bondName;
8. Decimal Operations
// Error: Operator '+' cannot be applied
const result = number + decimal.toNumber();
// Or
const result = decimal.plus(new Decimal(number));
File-Specific Fixes
reporting-engine.service.ts
- Cast
consolidatedDatatoRecord<string, unknown>before accessing properties - Cast
adequacyDatasimilarly
gru-controls.service.ts
- Remove
circuitBreakerEnabledfromupdateMany(not in schema) - Remove
issuanceWindowOpenfromupdateMany(not in schema) - Use
updateinstead or check schema
gru-command.service.ts
- Include bond relations to access
bondName,bondCode - Use
indexValueinstead ofprice - Add null check for
latestPricing.yield
dbis-admin.routes.ts / scb-admin.routes.ts
- Add type extension for
req.sovereignBankId - Or use
(req as any).sovereignBankId
sandbox.service.ts
- Cast
JsonValuetoRecord<string, unknown>before accessing properties - Use type guards for property access
Priority Order
- Quick: Missing imports, missing returns
- Medium: JsonValue casts, type conversions
- Complex: Prisma schema issues, property access
- Final: Edge cases, complex type issues