fix: resolve pre-existing TypeScript strictness build errors

- Add @types/node to API devDependencies
- Create HonoEnv type and apply to all routers + auth middleware for
  proper context.get/set("discordId") typing
- Use conditional spreads for exactOptionalPropertyTypes dailyChallenges
  in GameContext, tick engine, and prestige route
- Use conditional spread for optional signature in SaveRequest calls
- Add non-null assertions in shuffle/template index for noUncheckedIndexedAccess
- Cast GameState to never for Prisma InputJsonValue fields
- Exclude vite.config.ts from web tsconfig (it runs in Node context)
This commit is contained in:
2026-03-06 23:56:55 -08:00
committed by Naomi Carrigan
parent 078ae50e69
commit acda4c2fc4
10 changed files with 61 additions and 39 deletions
+1
View File
@@ -22,6 +22,7 @@
"devDependencies": {
"@nhcarrigan/eslint-config": "5.2.0",
"@nhcarrigan/typescript-config": "4.0.0",
"@types/node": "25.3.5",
"@vitest/coverage-v8": "3.0.8",
"eslint": "9.22.0",
"tsx": "4.19.3",
+3 -2
View File
@@ -1,7 +1,8 @@
import type { Context, Next } from "hono";
import type { MiddlewareHandler } from "hono";
import type { HonoEnv } from "../types/hono.js";
import { verifyToken } from "../services/jwt.js";
export const authMiddleware = async (context: Context, next: Next): Promise<void> => {
export const authMiddleware: MiddlewareHandler<HonoEnv> = async (context, next) => {
const authorization = context.req.header("Authorization");
if (!authorization?.startsWith("Bearer ")) {
+1 -1
View File
@@ -68,7 +68,7 @@ authRouter.get("/callback", async (context) => {
await prisma.gameState.create({
data: {
discordId: player.discordId,
state: initialState,
state: initialState as unknown as never,
updatedAt: now,
},
});
+3 -2
View File
@@ -1,5 +1,6 @@
import type { BuyPrestigeUpgradeRequest, GameState, PrestigeRequest } from "@elysium/types";
import { Hono } from "hono";
import type { HonoEnv } from "../types/hono.js";
import { prisma } from "../db/client.js";
import { authMiddleware } from "../middleware/auth.js";
import { DEFAULT_PRESTIGE_UPGRADES } from "../data/prestigeUpgrades.js";
@@ -10,7 +11,7 @@ import {
isEligibleForPrestige,
} from "../services/prestige.js";
export const prestigeRouter = new Hono();
export const prestigeRouter = new Hono<HonoEnv>();
prestigeRouter.use("*", authMiddleware);
@@ -55,7 +56,7 @@ prestigeRouter.post("/", async (context) => {
// Preserve daily challenges across the prestige reset and apply any crystal rewards
const finalState: GameState = {
...newState,
dailyChallenges: updatedDailyChallenges,
...(updatedDailyChallenges !== undefined ? { dailyChallenges: updatedDailyChallenges } : {}),
resources: {
...newState.resources,
crystals: newState.resources.crystals + challengeCrystals,
+2 -1
View File
@@ -5,10 +5,11 @@ import type {
} from "@elysium/types";
import { DEFAULT_PROFILE_SETTINGS } from "@elysium/types";
import { Hono } from "hono";
import type { HonoEnv } from "../types/hono.js";
import { prisma } from "../db/client.js";
import { authMiddleware } from "../middleware/auth.js";
export const profileRouter = new Hono();
export const profileRouter = new Hono<HonoEnv>();
const VALID_NUMBER_FORMATS = new Set(["suffix", "scientific", "engineering"]);
+2 -2
View File
@@ -25,7 +25,7 @@ const shuffleWithSeed = <T>(arr: T[], seed: number): T[] => {
const result = [...arr];
for (let i = result.length - 1; i > 0; i--) {
const j = Math.floor(seededRandom(seed + i) * (i + 1));
[result[i], result[j]] = [result[j], result[i]];
[result[i], result[j]] = [result[j]!, result[i]!];
}
return result;
};
@@ -48,7 +48,7 @@ export const generateDailyChallenges = (dateStr: string): DailyChallenge[] => {
return selectedTypes.map((type, index) => {
const templates = DAILY_CHALLENGE_TEMPLATES.filter((t) => t.type === type);
const templateIndex = Math.floor(seededRandom(seed + index * 100) * templates.length);
const template = templates[templateIndex];
const template = templates[templateIndex]!;
return {
id: `${dateStr}_${type}`,
+1
View File
@@ -0,0 +1 @@
export type HonoEnv = { Variables: { discordId: string } };