Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tls property in Bun.serve not available after 1.2.3 or higher #17772

Open
SPWizard01 opened this issue Feb 27, 2025 · 1 comment
Open

tls property in Bun.serve not available after 1.2.3 or higher #17772

SPWizard01 opened this issue Feb 27, 2025 · 1 comment
Labels
bug Something isn't working types An issue with TypeScript types

Comments

@SPWizard01
Copy link

SPWizard01 commented Feb 27, 2025

What version of Bun is running?

1.2.4+fd9a5ea66

What platform is your computer?

Microsoft Windows NT 10.0.26120.0 x64

What steps can reproduce the bug?

bun i @types/[email protected]

Bun.serve({
//... skipping for simplicity
 tls: undefined // works
})

bun i @types/[email protected]

observe that now typescript throws an error

What is the expected behavior?

tls property should be recognized

What do you see instead?

Object literal may only specify known properties, and 'tls' does not exist in type '((Omit<ServeOptions, "routes"> & { routes?: undefined; fetch: (this: Server, request: Request, server: Server) => Response | Promise<...>; }) | (Omit<...> & { ...; }) | WebSocketServeOptions<...>) & { ...; }'

Additional information

No response

@SPWizard01 SPWizard01 added bug Something isn't working types An issue with TypeScript types labels Feb 27, 2025
@Electroid
Copy link
Contributor

Hi there! I've been able to reproduce this issue.

The problem is that the TypeScript definitions for Bun.serve() don't properly include the TLSServeOptions interface. The tls property works correctly at runtime, but the TypeScript type checker doesn't recognize it as a valid property.

The issue appears to have been introduced in a recent version of the type definitions. Looking at the code, I see that the serve() function signature doesn't include TLSServeOptions in its union of parameter types.

I've created a reproduction case that confirms this behavior. For now, you can work around this by adding a type assertion:

Bun.serve({
  // other options
  tls: undefined,
  fetch: (req) => new Response("Hello")
} as any);

I'll create a fix for this issue to ensure the tls property is properly typed. Thank you for reporting!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working types An issue with TypeScript types
Projects
None yet
Development

No branches or pull requests

2 participants