Problem
The API layer files in api-src/ have zero TypeScript type annotations. Both files use implicit any for request/response objects, data parameters, and local variables. This is inconsistent with the rest of the codebase which is 100% TypeScript.
Files to Type
api-src/get-market-data.ts
Currently untyped:
export default allowCors(async (req, res) => {
const roomKey = getRoomName(req)
const roomData = await getRoomData(roomKey, get, set)
const { valueAdjustments } = roomData
set(roomKey, JSON.stringify(roomData))
res.status(200).json({ valueAdjustments })
})
Variables without types: req, res, roomKey, roomData, valueAdjustments
api-src/post-day-results.ts
Currently untyped:
const applyPositionsToMarket = (valueAdjustments, positions) => {
return Object.keys(valueAdjustments).reduce(
(acc, itemName) => { /* ... */ },
{ ...valueAdjustments }
)
}
export default allowCors(async (req, res) => {
const { body: { positions = {} } } = req
const roomKey = getRoomName(req)
const { valueAdjustments, ...roomData } = await getRoomData(roomKey, get, set)
// ...
})
Variables without types: valueAdjustments, positions, acc, itemName, itemPositionChange, variance, req, res, roomKey, roomData
Implementation Plan
Step 1: Determine the framework types
Check if the project uses Express, Vercel serverless, or another framework for the API. Look at api-etc/utils.ts for clues about the request/response types.
Step 2: Define shared types
Create types for the data structures used by both API endpoints. These should import from src/farmhand.d.ts:
interface RoomData {
valueAdjustments: Record<string, number>
// ... other fields from the room state stored in Redis
}
interface MarketDataResponse {
valueAdjustments: Record<string, number>
}
interface DayResultsRequest {
body: {
positions?: Record<string, number>
}
}
interface DayResultsResponse {
valueAdjustments: Record<string, number>
}
Step 3: Annotate api-src/get-market-data.ts
export default allowCors(async (req: Request, res: Response<MarketDataResponse>) => {
const roomKey = getRoomName(req)
const roomData = await getRoomData(roomKey, get, set) as RoomData
const { valueAdjustments } = roomData
set(roomKey, JSON.stringify(roomData))
res.status(200).json({ valueAdjustments })
})
Step 4: Annotate api-src/post-day-results.ts
const applyPositionsToMarket = (
valueAdjustments: Record<string, number>,
positions: Record<string, number>
): Record<string, number> => {
// ...
}
export default allowCors(async (req: Request<{}, DayResultsResponse, DayResultsRequest>, res: Response<DayResultsResponse>) => {
// ...
})
Step 5: Run type checker
Acceptance Criteria
api-src/get-market-data.ts has explicit types on all parameters and variables
api-src/post-day-results.ts has explicit types on all parameters and variables
- Shared types are defined and reused across both API files
- Zero implicit
any types remain in api-src/
npm run check:types passes with no errors
Problem
The API layer files in
api-src/have zero TypeScript type annotations. Both files use implicitanyfor request/response objects, data parameters, and local variables. This is inconsistent with the rest of the codebase which is 100% TypeScript.Files to Type
api-src/get-market-data.tsCurrently untyped:
Variables without types:
req,res,roomKey,roomData,valueAdjustmentsapi-src/post-day-results.tsCurrently untyped:
Variables without types:
valueAdjustments,positions,acc,itemName,itemPositionChange,variance,req,res,roomKey,roomDataImplementation Plan
Step 1: Determine the framework types
Check if the project uses Express, Vercel serverless, or another framework for the API. Look at
api-etc/utils.tsfor clues about the request/response types.Step 2: Define shared types
Create types for the data structures used by both API endpoints. These should import from
src/farmhand.d.ts:Step 3: Annotate
api-src/get-market-data.tsStep 4: Annotate
api-src/post-day-results.tsStep 5: Run type checker
Acceptance Criteria
api-src/get-market-data.tshas explicit types on all parameters and variablesapi-src/post-day-results.tshas explicit types on all parameters and variablesanytypes remain inapi-src/npm run check:typespasses with no errors