mostprodev
mostprodev15mo 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
ioB15mo ago
It does support async, how are you trying to call Deno.serve?
mostprodev
mostprodevOP15mo ago
Deno.serve(async (request) => {
"stuff"
});
Deno.serve(async (request) => {
"stuff"
});
ioB
ioB15mo ago
You're not returning a response, the type error is concerned with that.
mostprodev
mostprodevOP15mo 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
ioB15mo ago
another server is running on port 8000
mostprodev
mostprodevOP15mo ago
Yes.
ioB
ioB15mo 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
mostprodevOP15mo ago
Okay, thanks!
shawnbu
shawnbu15mo ago
I get that also. Just need to return a new Response()