Skip to content

Conversation

Komiriko
Copy link

@Komiriko Komiriko commented Oct 17, 2025

Summary by CodeRabbit

  • Chores

    • Updated Bun type definitions to the latest version for improved compatibility.
  • Refactor

    • Refined type system for server configuration with enhanced generic type support to improve type inference and overall compatibility.

Copy link

coderabbitai bot commented Oct 17, 2025

Walkthrough

This PR bumps the @types/bun dependency to v1.3.0 and updates the Serve and Server type aliases in the universal server module to use generic parameterization with unknown, aligning with the updated Bun type definitions.

Changes

Cohort / File(s) Change Summary
Dependency Update
package.json
Updated @types/bun devDependency from ^1.2.12 to ^1.3.0
Type Alias Adjustments
src/universal/server.ts
Modified Serve and Server type aliases to reference Bun types with generic unknown parameter: Serve now checks BunServe.Options<unknown> instead of BunServe, and Server now checks BunServer<unknown> instead of BunServer

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

The changes span type system adjustments that affect public API exports. While the modifications are localized and repetitive (applying generic parameterization), they require careful verification of TypeScript type inference behavior and potential downstream impacts on consumers relying on these type definitions.

Poem

🐰 A rabbit hops through types with glee,
Generic unknown flows wild and free,
Bun's newest types now in our sight,
Type aliases dance, aligned just right! 🎯

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The pull request title "[#1494] : [Hook] onRequest server hook parameters are typed as any (Bun 1.3.0)" is partially related to the changeset. It correctly references the Bun 1.3.0 version upgrade (evident from the package.json devDependency bump from ^1.2.12 to ^1.3.0) and indicates the context of the issue being fixed. The title describes the problem being addressed (parameters typed as any) and the version context, which aligns with the actual changes made to update the Serve and Server type aliases in src/universal/server.ts. While the title focuses on the issue context rather than the implementation details of how the types were updated (adding generic unknown parameters), it remains a real and relevant aspect of the changeset.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

@Komiriko
Copy link
Author

Komiriko commented Oct 17, 2025

#1494 I tried to explain in detail in the issue 🥺

@Komiriko Komiriko changed the title [#1494] : [Hook] onRequest server hook parameters are typed as any [#1494] : [Hook] onRequest server hook parameters are typed as any (Bun 1.3.0) Oct 17, 2025
Copy link

@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

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 272460a and 8944978.

⛔ Files ignored due to path filters (1)
  • bun.lock is excluded by !**/*.lock
📒 Files selected for processing (2)
  • package.json (1 hunks)
  • src/universal/server.ts (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/universal/server.ts (1)
src/types.ts (1)
  • IsAny (842-842)
🔇 Additional comments (2)
package.json (1)

199-199: Version bump aligns with Bun 1.3 typings.

Upgrade looks good and matches the type changes in src/universal/server.ts. Please run the existing type test suite to confirm no regressions in downstream adapters. Based on learnings.

src/universal/server.ts (1)

125-126: Switch to Bun generics with unknown — LGTM and solves the any leak.

Using BunServe.Options and BunServer (with IsAny fallback) tightens types and should fix onRequest params being any while staying backward compatible. Based on learnings.

To lock this in, add a tiny type test (using expect-type already in devDeps):

// test/type-system/on-request-server.d.ts
import type { Server } from '../../src/universal/server'
import { expectType } from 'expect-type'

declare function onRequest(server: Server): void
// Ensure Server is not any
type IsAny<T> = 0 extends 1 & T ? true : false
expectType<false>({} as IsAny<Server>)

Run: bun run test:types

@@ -1,4 +1,4 @@
import type { Serve as BunServe, Server as BunServer } from 'bun'
import { Serve as BunServe, type Server as BunServer } from 'bun'
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion | 🟠 Major

🧩 Analysis chain

Avoid runtime import of "bun" in universal types by using type-only module import.

Importing Serve as a value can survive emit in some setups (e.g., verbatimModuleSyntax) and accidentally pull "bun" at runtime in non-Bun targets. Prefer a pure type import for safety.

Apply:

-import { Serve as BunServe, type Server as BunServer } from 'bun'
+import type * as BunTypes from 'bun'

And update aliases:

-export type Serve = IsAny<BunServe.Options<unknown>> extends false ? BunServe.Options<unknown> : ServeOptions
-export type Server = IsAny<BunServer<unknown>> extends false ? BunServer<unknown> : ServerOptions
+export type Serve = IsAny<BunTypes.Serve.Options<unknown>> extends false ? BunTypes.Serve.Options<unknown> : ServeOptions
+export type Server = IsAny<BunTypes.Server<unknown>> extends false ? BunTypes.Server<unknown> : ServerOptions

Also applies to: 125-126


🏁 Script executed:

#!/bin/bash
# Verify we don't emit runtime imports of "bun" in built artifacts
# (run after your normal build)
rg -nP 'from\s+[\'"]bun[\'"]' -g 'dist/**/universal/*.js' -S || echo "OK: no runtime bun imports found in dist/universal"

Length of output: 68



---

🏁 Script executed:

```shell
#!/bin/bash
# Examine the source file to understand current import structure
echo "=== Examining src/universal/server.ts ===" 
head -20 src/universal/server.ts

echo ""
echo "=== Checking lines around 125-126 ===" 
sed -n '120,130p' src/universal/server.ts

Length of output: 944


🏁 Script executed:

#!/bin/bash
# Check if dist/universal exists and search for bun imports using alternative escaping
if [ -d dist/universal ]; then
  echo "=== Checking for bun imports in dist/universal ==="
  rg -n 'from.*bun' dist/universal/ --type js 2>/dev/null || echo "No matches found or directory structure differs"
else
  echo "dist/universal not found - build artifacts may not exist"
  find . -name "*.js" -path "*/dist/*" -type f 2>/dev/null | head -5 || echo "No dist files found"
fi

Length of output: 1140


🏁 Script executed:

#!/bin/bash
# Verify the overall structure and search for any bun-related imports in the source
echo "=== Source file import section ===" 
rg -n 'import.*bun' src/universal/ --type ts 2>/dev/null || echo "No matches found"

Length of output: 246


🏁 Script executed:

#!/bin/bash
# Check all usages of BunServe and BunServer in the file
echo "=== All usages of BunServe ===" 
rg -n 'BunServe' src/universal/server.ts

echo ""
echo "=== All usages of BunServer ===" 
rg -n 'BunServer' src/universal/server.ts

Length of output: 517


Fix value import of "Serve" to prevent runtime "bun" imports in universal code.

The Serve import on line 1 is imported as a value but only used in type positions (lines 125–126). With compiler options like verbatimModuleSyntax, this will emit a runtime import of "bun" in the compiled output, breaking compatibility in non-Bun environments.

Apply:

-import { Serve as BunServe, type Server as BunServer } from 'bun'
+import type * as BunTypes from 'bun'

Then update lines 125–126:

-export type Serve = IsAny<BunServe.Options<unknown>> extends false ? BunServe.Options<unknown> : ServeOptions
-export type Server = IsAny<BunServer<unknown>> extends false ? BunServer<unknown> : ServerOptions
+export type Serve = IsAny<BunTypes.Serve.Options<unknown>> extends false ? BunTypes.Serve.Options<unknown> : ServeOptions
+export type Server = IsAny<BunTypes.Server<unknown>> extends false ? BunTypes.Server<unknown> : ServerOptions

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In src/universal/server.ts around line 1 and lines 125–126, the import currently
brings Serve as a runtime value which causes a runtime import of "bun"; change
the import to a type-only import (import type { Serve as BunServe, Server as
BunServer } from 'bun') and update the usages at lines 125–126 to be type
annotations only (remove any runtime references to BunServe/BunServer so they
are used purely as types).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant