chore(ts): eliminate the remaining 4 \as any\ casts in production code
Followup to #447. The audit ran on \`as unknown as\` first; this PR closes out \`as any\` separately. After this, \`grep -rn ' as any\\b' apps/ packages/\` returns 0 (excluding tests and node_modules). ## Sites fixed **\`apps/journal/server.ts\`** + **\`packages/jobs/src/types.ts\`** — \`komootBulkImportJob as any\`. The job had a typed payload (\`JobDefinition<KomootBulkImportData>\`) but the worker's \`JobDefinition[]\` array forced a contravariance cast at every site that mixed typed and untyped jobs. Dropped the generic from \`JobDefinition\` entirely; handlers narrow their own \`job.data\`. Only one job (komoot-bulk-import) used the generic, so the surface is tiny. **\`apps/journal/app/lib/connected-services/fit.ts\`** + same pattern in \`routes/sync.import.\$provider.server.ts\` — \`parser.parse(buffer as any, (err: unknown, d: any) => ...)\`. fit-file-parser's TypeScript types require \`Buffer<ArrayBuffer>\` specifically; a generic Node \`Buffer\` is structurally \`Buffer<ArrayBufferLike>\` (which includes SharedArrayBuffer). The runtime accepts either, so narrowed the cast to \`as Buffer<ArrayBuffer>\` — still a cast, but precise about what we're asserting and why. Removed the \`(err, d: any) => …\` ad-hoc callback typings; the library exports a proper \`FitParserCallback\`. **\`apps/mobile/lib/editor/RouteMap.tsx\`** — \`onLongPress\` handler took \`(event: any)\`. maplibre-react-native v11 generates the event type via React Native codegen but doesn't re-export it as a public TypeScript type. Replaced with a local structural slice of the parts we actually read. Net: 4 \`as any\` sites in prod code → 0. \`pnpm typecheck\` / \`lint\` / \`test\` all green. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
2fc09165da
commit
b0b58d36fb
6 changed files with 31 additions and 16 deletions
|
|
@ -6,20 +6,22 @@ type KomootCreds =
|
|||
| { mode: "public"; komootUserId: string }
|
||||
| { mode: "authenticated"; email: string; encryptedPassword: string; komootUserId: string };
|
||||
|
||||
interface KomootBulkImportData extends Record<string, unknown> {
|
||||
interface KomootBulkImportData {
|
||||
batchId: string;
|
||||
userId: string;
|
||||
creds: KomootCreds;
|
||||
}
|
||||
|
||||
export const komootBulkImportJob: JobDefinition<KomootBulkImportData> = {
|
||||
export const komootBulkImportJob: JobDefinition = {
|
||||
name: "komoot-bulk-import",
|
||||
retryLimit: 1,
|
||||
expireInSeconds: 1800,
|
||||
async handler(jobs) {
|
||||
const batch = Array.isArray(jobs) ? jobs : [jobs];
|
||||
for (const job of batch) {
|
||||
const { batchId, userId, creds } = job.data;
|
||||
// pg-boss serialized payload — caller (enqueueOptional) wrote it
|
||||
// as KomootBulkImportData. Narrow at the boundary.
|
||||
const { batchId, userId, creds } = job.data as KomootBulkImportData;
|
||||
logger.info({ batchId, userId }, "komoot bulk import job started");
|
||||
await runKomootBulkImport(batchId, userId, creds);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,10 +10,12 @@ import { generateGpx } from "@trails-cool/gpx";
|
|||
export async function fitToGpx(buffer: Buffer, name: string): Promise<string | null> {
|
||||
const parsed = await new Promise<Record<string, unknown>>((resolve, reject) => {
|
||||
const parser = new FitParser({ force: true });
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
parser.parse(buffer as any, (error: unknown, data: any) => {
|
||||
// fit-file-parser's typing requires `Buffer<ArrayBuffer>` specifically;
|
||||
// a generic Node `Buffer` is structurally `Buffer<ArrayBufferLike>`.
|
||||
// The runtime accepts either, so coerce the underlying buffer slot.
|
||||
parser.parse(buffer as Buffer<ArrayBuffer>, (error, data) => {
|
||||
if (error) reject(error);
|
||||
else resolve(data ?? {});
|
||||
else resolve((data ?? {}) as Record<string, unknown>);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -85,8 +85,11 @@ export async function syncImportProviderAction(request: Request, provider: strin
|
|||
const { default: FitParser } = await import("fit-file-parser");
|
||||
const parsed = await new Promise<Record<string, unknown>>((resolve, reject) => {
|
||||
const parser = new FitParser({ force: true });
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
parser.parse(buffer as any, (err: unknown, d: any) => (err ? reject(err) : resolve(d ?? {})));
|
||||
// See lib/connected-services/fit.ts for the same Buffer<ArrayBuffer>
|
||||
// narrowing rationale.
|
||||
parser.parse(buffer as Buffer<ArrayBuffer>, (err, d) =>
|
||||
err ? reject(err) : resolve((d ?? {}) as Record<string, unknown>),
|
||||
);
|
||||
});
|
||||
const records = (parsed.records ?? []) as Array<{
|
||||
position_lat?: number;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue