# 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
```typescript
// Error: Cannot find name 'uuidv4'
import { v4 as uuidv4 } from 'uuid';
```

### 2. Missing Return
```typescript
// Error: Not all code paths return
catch (error) {
  return next(error);  // Add 'return'
}
```

### 3. JsonValue Cast
```typescript
// Error: Type 'Record<string, unknown>' is not assignable
metadata: data as Prisma.InputJsonValue
```

### 4. Type Conversion via Unknown
```typescript
// Error: Conversion may be mistake
metadata: request as unknown as Record<string, unknown>
```

### 5. Unknown Type Assertion
```typescript
// Error: Property is of type 'unknown'
const data = consolidatedData as Record<string, unknown>;
const bankDetails = data.bankDetails as BankDetails;
```

### 6. Null Safety
```typescript
// Error: Possibly 'null'
if (value) {
  // Use value
}
// Or
const result = value!.property;
```

### 7. Prisma Property Access
```typescript
// 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
```typescript
// 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 `consolidatedData` to `Record<string, unknown>` before accessing properties
- Cast `adequacyData` similarly

### gru-controls.service.ts
- Remove `circuitBreakerEnabled` from `updateMany` (not in schema)
- Remove `issuanceWindowOpen` from `updateMany` (not in schema)
- Use `update` instead or check schema

### gru-command.service.ts
- Include bond relations to access `bondName`, `bondCode`
- Use `indexValue` instead of `price`
- 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 `JsonValue` to `Record<string, unknown>` before accessing properties
- Use type guards for property access

## Priority Order

1. **Quick**: Missing imports, missing returns
2. **Medium**: JsonValue casts, type conversions
3. **Complex**: Prisma schema issues, property access
4. **Final**: Edge cases, complex type issues

