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