mostprodev
mostprodev17mo ago

Deno Types

What is the Deno.ServeHandler type?
No overload matches this call.
Overload 1 of 3, '(handler: ServeHandler): Server', gave the following error.
Argument of type '(request: Request) => Promise<Response | undefined>' is not assignable to parameter of type 'ServeHandler'.
Type 'Promise<Response | undefined>' is not assignable to type 'Response | Promise<Response>'.
Type 'Promise<Response | undefined>' is not assignable to type 'Promise<Response>'.
Type 'Response | undefined' is not assignable to type 'Response'.
Type 'undefined' is not assignable to type 'Response'. Overload 2 of 3, '(options: ServeInit & (ServeOptions | ServeTlsOptions)): Server', gave the following error.
No overload matches this call.
Overload 1 of 3, '(handler: ServeHandler): Server', gave the following error.
Argument of type '(request: Request) => Promise<Response | undefined>' is not assignable to parameter of type 'ServeHandler'.
Type 'Promise<Response | undefined>' is not assignable to type 'Response | Promise<Response>'.
Type 'Promise<Response | undefined>' is not assignable to type 'Promise<Response>'.
Type 'Response | undefined' is not assignable to type 'Response'.
Type 'undefined' is not assignable to type 'Response'. Overload 2 of 3, '(options: ServeInit & (ServeOptions | ServeTlsOptions)): Server', gave the following error.
Does it not support async?
9 Replies
ioB
ioB17mo ago
It does support async, how are you trying to call Deno.serve?
mostprodev
mostprodevOP17mo ago
Deno.serve(async (request) => {
"stuff"
});
Deno.serve(async (request) => {
"stuff"
});
ioB
ioB17mo ago
You're not returning a response, the type error is concerned with that.
mostprodev
mostprodevOP17mo ago
Makes sense. What about
error: Uncaught AddrInUse: Address already in use (os error 48)
Deno.serve(async (request) => {
error: Uncaught AddrInUse: Address already in use (os error 48)
Deno.serve(async (request) => {
? Is there a way to set another port?
ioB
ioB17mo ago
another server is running on port 8000
mostprodev
mostprodevOP17mo ago
Yes.
ioB
ioB17mo ago
Yes, add the port as an argument:
Deno.serve({ port: 1000 },()=>{
return new Response("hi")
})
Deno.serve({ port: 1000 },()=>{
return new Response("hi")
})
mostprodev
mostprodevOP17mo ago
Okay, thanks!
shawnbu
shawnbu17mo ago
I get that also. Just need to return a new Response()

Did you find this page helpful?