Skip to content

fix: resolve typecheck and lint errors across the codebase#352

Merged
HugoRCD merged 1 commit into
mainfrom
fix/typecheck-lint
May 24, 2026
Merged

fix: resolve typecheck and lint errors across the codebase#352
HugoRCD merged 1 commit into
mainfrom
fix/typecheck-lint

Conversation

@HugoRCD
Copy link
Copy Markdown
Owner

@HugoRCD HugoRCD commented May 24, 2026

🔗 Linked issue

📚 Description

📝 Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

Summary by CodeRabbit

Release Notes

  • Refactor

    • Improved TypeScript type safety and casting consistency across adapters, middleware, and framework integrations.
    • Made request logger typing optional in Express to handle cases where middleware may not be present.
    • Enhanced handler and middleware type signatures for better compatibility.
  • Tests

    • Updated test mocks and assertions to align with improved type signatures and logger interfaces.
  • Chores

    • Enabled experimental TypeScript decorator support in compiler options.
    • Updated configuration examples for Nitro and Vite builds.

Review Change Stack

@HugoRCD HugoRCD self-assigned this May 24, 2026
@vercel
Copy link
Copy Markdown

vercel Bot commented May 24, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
evlog-docs Ready Ready Preview, Comment, Open in v0 May 24, 2026 4:41pm
just-use-evlog Ready Ready Preview, Comment May 24, 2026 4:41pm

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 24, 2026

Thank you for following the naming conventions! 🙏

@github-actions github-actions Bot added the bug Something isn't working label May 24, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 24, 2026

📝 Walkthrough

Walkthrough

This PR refactors the evlog TypeScript type system to improve safety and consistency. Changes include introducing explicit RequestLogger typing across framework integrations, broadening type signatures to accept partial or undefined values, updating adapter tests to use the apiKey option name, and aligning test mocks and assertions with the enhanced interface.

Changes

Type system and interface alignment

Layer / File(s) Summary
RequestLogger framework module augmentations
packages/evlog/src/fastify/index.ts, packages/evlog/src/express/index.ts, packages/evlog/src/shared/middleware.ts
Fastify and Express module augmentations now type request.log as RequestLogger rather than any or untyped; shared middleware noop logger includes setLevel() stub to match the interface.
Type signature broadening and assertion improvements
packages/evlog/src/adapters/axiom.ts, packages/evlog/src/utils.ts, packages/evlog/src/audit.ts, packages/evlog/src/catalog.ts, packages/evlog/src/next/instrumentation.ts, packages/evlog/src/next/middleware.ts, packages/evlog/src/sveltekit/index.ts
applyApiKeyAlias and filterSafeHeaders signatures broaden to accept Partial<...> inputs with undefined values; audit, catalog, and instrumentation code add explicit type casts via unknown intermediates; Next middleware headers type now includes both set and get methods; SvelteKit resolve parameter accepts variadic args and union return type.
Adapter contract updates: token to apiKey
packages/evlog/test/adapters/axiom.test.ts, packages/evlog/test/adapters/better-stack.test.ts
Axiom and Better Stack adapter tests updated throughout to pass apiKey instead of token/sourceToken; assertions for Authorization header values, endpoint selection, body transformation, timeout behavior, and error handling remain functionally identical but reflect the new option name.
Test helpers, mocks, and mock logger stubs
packages/evlog/test/ai/ai.test.ts, packages/evlog/test/better-auth/better-auth.test.ts, packages/evlog/test/helpers/framework.ts, packages/evlog/test/nitro/plugin.test.ts
Test mock loggers extended with setLevel method stubs; vitest generic syntax updated from tuple form ([Ctx]) to function-parameter form ((ctx: Ctx) => ...); helper functions align mock surfaces with the expanded RequestLogger interface.
Framework test assertion updates
packages/evlog/test/frameworks/fastify.test.ts, packages/evlog/test/frameworks/nestjs.test.ts, packages/evlog/test/frameworks/sveltekit.test.ts, packages/evlog/test/better-auth/better-auth.test.ts, packages/evlog/test/frameworks/elysia.test.ts
Fastify and NestJS tests use explicit RequestLogger casts and non-null assertions for request.log access; SvelteKit mock resolve callback updated with typed signature; Elysia helper loosens app parameter to structural interface; better-auth and other tests use updated mock-call casting patterns.
Core logger test context casting
packages/evlog/test/core/logger.test.ts, packages/evlog/test/core/logger-request-logger.test.ts
Logger tests updated to use typed array casts with non-null assertions when reading context.requestLogs entries; test for primitive key overwrite switched to use phase instead of status.
Next.js handler and middleware test updates
packages/evlog/test/next/handler.test.ts, packages/evlog/test/next/middleware.test.ts, packages/evlog/test/next/stream.test.ts
Handler tests update wrapped function signatures to include explicit Request parameter; middleware assertions use non-null assertions for request.headers access; stream drain extraction uses unknown-based casting for mock call tuple access.
Nitro test updates
packages/evlog/test/nitro/errorHandler.test.ts, packages/evlog/test/nitro/plugin.test.ts, packages/evlog/test/nitro-v3/cloudflare-durable-build.test.ts
Error handler mocks updated to accept any[] variadic args and include third-argument casts; plugin tests extend mock log stubs with info/warn/setLevel; header typing broadened to accept Partial with undefined values; describe.skipIf chaining reordered.
Configuration updates
examples/tanstack-start/nitro.config.ts, examples/tanstack-start/vite.config.ts, packages/evlog/tsconfig.json
Nitro config example switches from defineConfig wrapper to satisfies NitroConfig assertion; Vite config removes Sentry externalization from Nitro plugin; TypeScript config enables experimentalDecorators and emitDecoratorMetadata.

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description contains only the repository template with no actual implementation details, rationale, or completed checklist items. Required sections for 'Description' and linked issues are unfilled. Fill in the Description section explaining the typecheck/lint errors resolved, provide rationale for changes, and complete the checklist items or explain why they're not applicable.
Docstring Coverage ⚠️ Warning Docstring coverage is 14.29% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix: resolve typecheck and lint errors across the codebase' accurately reflects the PR's primary objective to resolve typecheck and lint errors, matching the substantial changes across multiple files and test suites.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/typecheck-lint

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 24, 2026

Benchmark report

Bundle size

Threshold: 5% · 🔴 larger · 🟡 warning · 🟢 smaller · ⚪ unchanged · 🆕 new

Status Entry Base (gzip) Current (gzip) Change Raw delta
🔴 utils 1.58 kB 1.78 kB +12.6% +449 B
framework/express 727 B 734 B +1.0% +49 B
framework/nitro 7.16 kB 7.23 kB +0.9% +196 B
framework/nestjs 1.25 kB 1.26 kB +0.2% +41 B
adapter/better-stack 1.26 kB 1.26 kB +0.2% 0 B
adapter/posthog 1.47 kB 1.47 kB +0.1% 0 B
adapter/axiom 1.50 kB 1.50 kB +0.1% 0 B
adapter/datadog 2.48 kB 2.48 kB +0.1% 0 B
adapter/otlp 2.14 kB 2.14 kB +0.1% 0 B
core (index) 2.15 kB 2.16 kB +0.1% 0 B
adapter/hyperdx 1.18 kB 1.18 kB +0.1% 0 B
workers 1.30 kB 1.31 kB +0.1% 0 B
framework/ai 4.67 kB 4.67 kB 0.0% 0 B
adapter/fs 3.35 kB 3.35 kB 0.0% 0 B
adapter/sentry 2.40 kB 2.40 kB 0.0% 0 B
framework/vite 2.40 kB 2.40 kB 0.0% 0 B
enrichers 1.99 kB 1.99 kB 0.0% 0 B
error 1.57 kB 1.57 kB 0.0% 0 B
pipeline 1.35 kB 1.35 kB 0.0% 0 B
http 1.24 kB 1.24 kB 0.0% 0 B
framework/fastify 1.02 kB 1.02 kB 0.0% 0 B
toolkit 781 B 781 B 0.0% 0 B
framework/hono 615 B 615 B 0.0% 0 B
browser 289 B 289 B 0.0% 0 B
client 128 B 128 B 0.0% 0 B
types 31 B 31 B 0.0% 0 B
framework/next 5.20 kB 5.20 kB -0.0% 0 B
framework/sveltekit 1.59 kB 1.59 kB -0.1% 0 B
framework/elysia 1.33 kB 1.33 kB -0.1% 0 B
logger 229 B 225 B -1.7% 0 B
Total 54.33 kB 54.61 kB +0.5% +735 B

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/evlog/src/utils.ts (1)

127-137: 🛠️ Refactor suggestion | 🟠 Major | ⚡ Quick win

Add JSDoc for the updated public API.

filterSafeHeaders is exported and was changed, but it still has no JSDoc block.

Proposed fix
+/**
+ * Returns a copy of headers excluding sensitive keys and undefined values.
+ */
 export function filterSafeHeaders(headers: Partial<Record<string, string | undefined>>): Record<string, string> {
   const safeHeaders: Record<string, string> = {}

   for (const [key, value] of Object.entries(headers)) {
     if (value !== undefined && !SENSITIVE_HEADERS.includes(key.toLowerCase())) {
       safeHeaders[key] = value
     }
   }

   return safeHeaders
 }

As per coding guidelines, packages/evlog/src/**/*.{ts,tsx}: Add JSDoc comments on all public APIs.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/evlog/src/utils.ts` around lines 127 - 137, Add a JSDoc comment for
the exported function filterSafeHeaders so it documents purpose, parameters and
return value; specifically, above the filterSafeHeaders declaration describe
what the function does (filters out undefined and sensitive headers), document
the headers parameter type and that keys/values are strings
(Partial<Record<string,string|undefined>>), and document the returned
Record<string,string> of only safe headers; include any relevant tags like
`@param` and `@returns` and mark it as part of the public API.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/evlog/src/nestjs/index.ts`:
- Line 36: The type declares Request.log as required but the middleware may exit
early before assigning req.log; make the type safe by changing the declaration
to optional (e.g., Request.log?: RequestLogger) and update any call sites that
access req.log to handle undefined (guard with if (req.log) or provide a
fallback), or alternatively ensure the middleware always assigns req.log before
any early return; update the Request interface and all references to Request.log
/ req.log / RequestLogger accordingly so the runtime and types match.

In `@packages/evlog/test/core/logger-request-logger.test.ts`:
- Around line 46-47: The test is bypassing type safety by forcing string values
into the numeric-only status field; update the overwrite test to use a
non-reserved, neutral key instead (e.g., replace logger.set({ status: 'pending'
as unknown as number }) and logger.set({ status: 'complete' as unknown as number
}) with logger.set({ phase: 'pending' }) and logger.set({ phase: 'complete' })
), adjusting any assertions that check these values to reference phase rather
than status so the test no longer masks type contract regressions; keep using
the same logger.set function name and test flow.

In `@packages/evlog/test/frameworks/fastify.test.ts`:
- Line 38: The test is reading request.log.set without guarding against
undefined; update the boolean guards (e.g., the hasLogger check and the
include/exclude logger checks) to use optional chaining and a safe typeof check
such as verifying typeof request.log?.set === 'function' (or request.log != null
&& typeof request.log?.set === 'function') so accessing .set won't throw if
request.log is undefined; apply this change to the hasLogger variable and the
include/exclude logger checks referenced in the Fastify test.

---

Outside diff comments:
In `@packages/evlog/src/utils.ts`:
- Around line 127-137: Add a JSDoc comment for the exported function
filterSafeHeaders so it documents purpose, parameters and return value;
specifically, above the filterSafeHeaders declaration describe what the function
does (filters out undefined and sensitive headers), document the headers
parameter type and that keys/values are strings
(Partial<Record<string,string|undefined>>), and document the returned
Record<string,string> of only safe headers; include any relevant tags like
`@param` and `@returns` and mark it as part of the public API.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 9dab7f2e-f06f-46df-bb55-6d5e8b55e836

📥 Commits

Reviewing files that changed from the base of the PR and between aa3ae0d and 96ae7bf.

📒 Files selected for processing (31)
  • packages/evlog/src/adapters/axiom.ts
  • packages/evlog/src/audit.ts
  • packages/evlog/src/catalog.ts
  • packages/evlog/src/fastify/index.ts
  • packages/evlog/src/nestjs/index.ts
  • packages/evlog/src/next/instrumentation.ts
  • packages/evlog/src/next/middleware.ts
  • packages/evlog/src/shared/middleware.ts
  • packages/evlog/src/sveltekit/index.ts
  • packages/evlog/src/utils.ts
  • packages/evlog/test/adapters/axiom.test.ts
  • packages/evlog/test/adapters/better-stack.test.ts
  • packages/evlog/test/ai/ai.test.ts
  • packages/evlog/test/better-auth/better-auth.test.ts
  • packages/evlog/test/core/logger-request-logger.test.ts
  • packages/evlog/test/core/logger.test.ts
  • packages/evlog/test/frameworks/elysia.test.ts
  • packages/evlog/test/frameworks/fastify.test.ts
  • packages/evlog/test/frameworks/nestjs.test.ts
  • packages/evlog/test/frameworks/sveltekit.test.ts
  • packages/evlog/test/helpers/framework.ts
  • packages/evlog/test/http/http.test.ts
  • packages/evlog/test/next/handler.test.ts
  • packages/evlog/test/next/middleware.test.ts
  • packages/evlog/test/next/stream.test.ts
  • packages/evlog/test/nitro-v3/cloudflare-durable-build.test.ts
  • packages/evlog/test/nitro/errorHandler.test.ts
  • packages/evlog/test/nitro/plugin-enrichment.test.ts
  • packages/evlog/test/nitro/plugin.test.ts
  • packages/evlog/test/toolkit/toolkit.test.ts
  • packages/evlog/tsconfig.json

Comment thread packages/evlog/src/nestjs/index.ts Outdated
Comment thread packages/evlog/test/core/logger-request-logger.test.ts Outdated
Comment thread packages/evlog/test/frameworks/fastify.test.ts Outdated
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 24, 2026

npm i https://pkg.pr.new/evlog@352
npm i https://pkg.pr.new/@evlog/nuxthub@352

commit: b8b441a

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/evlog/test/next/stream.test.ts`:
- Line 76: Replace the repeated chained unknown casts by adding a small typed
helper (e.g. lastMockArg<T>(mockFn: { calls: unknown[][] }, argIndex = 0): T |
undefined) and use it to obtain the last createInstrumentation call argument;
for example call lastMockArg<ExpectedType>(createInstrumentation, 0) instead of
the long cast used in the tests (the symbol to update is createInstrumentation
and the tests that assign lastCall on lines using that cast). This centralizes
the cast, makes types explicit, and reuse it for the other occurrences at 91,
103 and 115.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: bcf41dc3-6c99-4327-aeae-0c28a5fcbbd9

📥 Commits

Reviewing files that changed from the base of the PR and between 96ae7bf and b8b441a.

📒 Files selected for processing (33)
  • examples/tanstack-start/nitro.config.ts
  • examples/tanstack-start/vite.config.ts
  • packages/evlog/src/adapters/axiom.ts
  • packages/evlog/src/audit.ts
  • packages/evlog/src/catalog.ts
  • packages/evlog/src/express/index.ts
  • packages/evlog/src/fastify/index.ts
  • packages/evlog/src/next/instrumentation.ts
  • packages/evlog/src/next/middleware.ts
  • packages/evlog/src/shared/middleware.ts
  • packages/evlog/src/sveltekit/index.ts
  • packages/evlog/src/utils.ts
  • packages/evlog/test/adapters/axiom.test.ts
  • packages/evlog/test/adapters/better-stack.test.ts
  • packages/evlog/test/ai/ai.test.ts
  • packages/evlog/test/better-auth/better-auth.test.ts
  • packages/evlog/test/core/logger-request-logger.test.ts
  • packages/evlog/test/core/logger.test.ts
  • packages/evlog/test/frameworks/elysia.test.ts
  • packages/evlog/test/frameworks/fastify.test.ts
  • packages/evlog/test/frameworks/nestjs.test.ts
  • packages/evlog/test/frameworks/sveltekit.test.ts
  • packages/evlog/test/helpers/framework.ts
  • packages/evlog/test/http/http.test.ts
  • packages/evlog/test/next/handler.test.ts
  • packages/evlog/test/next/middleware.test.ts
  • packages/evlog/test/next/stream.test.ts
  • packages/evlog/test/nitro-v3/cloudflare-durable-build.test.ts
  • packages/evlog/test/nitro/errorHandler.test.ts
  • packages/evlog/test/nitro/plugin-enrichment.test.ts
  • packages/evlog/test/nitro/plugin.test.ts
  • packages/evlog/test/toolkit/toolkit.test.ts
  • packages/evlog/tsconfig.json


expect(createInstrumentation).toHaveBeenCalled()
const lastCall = createInstrumentation.mock.calls.at(-1)![0] as { drain?: (ctx: unknown) => Promise<void> }
const lastCall = ((createInstrumentation.mock.calls.at(-1)!) as unknown as [unknown])[0] as unknown as { drain?: (ctx: unknown) => Promise<void> }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick | 🔵 Trivial | ⚡ Quick win

Replace repeated unknown cast chains with a typed mock-call helper.

The current extraction pattern is hard to read and fragile. Use one typed helper for the last createInstrumentation arg to keep tests safer and maintainable.

♻️ Proposed refactor
+type InstrumentationArg = { drain?: (ctx: unknown) => Promise<void> }
+
+function getLastCreateInstrumentationArg(): InstrumentationArg {
+  const call = createInstrumentation.mock.calls.at(-1)
+  expect(call).toBeDefined()
+  return call![0] as InstrumentationArg
+}
+
   it('composes user drain and server drain so both run on each event', async () => {
@@
-    const lastCall = ((createInstrumentation.mock.calls.at(-1)!) as unknown as [unknown])[0] as unknown as { drain?: (ctx: unknown) => Promise<void> }
+    const lastCall = getLastCreateInstrumentationArg()
@@
   it('uses only user drain when server is off', async () => {
@@
-    const lastCall = ((createInstrumentation.mock.calls.at(-1)!) as unknown as [unknown])[0] as unknown as { drain?: (ctx: unknown) => Promise<void> }
+    const lastCall = getLastCreateInstrumentationArg()
@@
   it('uses only server drain when no user drain is configured', async () => {
@@
-    const lastCall = ((createInstrumentation.mock.calls.at(-1)!) as unknown as [unknown])[0] as unknown as { drain?: (ctx: unknown) => Promise<void> }
+    const lastCall = getLastCreateInstrumentationArg()
@@
   it('omits drain entirely when neither side is configured', async () => {
@@
-    const lastCall = ((createInstrumentation.mock.calls.at(-1)!) as unknown as [unknown])[0] as unknown as { drain?: unknown }
+    const lastCall = getLastCreateInstrumentationArg()
For Vitest 4.x, what is the recommended typed pattern for reading the latest mock call argument from `vi.fn().mock.calls` without chained `unknown` casts?

Also applies to: 91-91, 103-103, 115-115

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/evlog/test/next/stream.test.ts` at line 76, Replace the repeated
chained unknown casts by adding a small typed helper (e.g.
lastMockArg<T>(mockFn: { calls: unknown[][] }, argIndex = 0): T | undefined) and
use it to obtain the last createInstrumentation call argument; for example call
lastMockArg<ExpectedType>(createInstrumentation, 0) instead of the long cast
used in the tests (the symbol to update is createInstrumentation and the tests
that assign lastCall on lines using that cast). This centralizes the cast, makes
types explicit, and reuse it for the other occurrences at 91, 103 and 115.

@HugoRCD HugoRCD merged commit 4c21fe6 into main May 24, 2026
20 checks passed
@HugoRCD HugoRCD deleted the fix/typecheck-lint branch May 24, 2026 16:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant