mostprodev
mostprodev11mo 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
ioB11mo ago
It does support async, how are you trying to call Deno.serve?
mostprodev
mostprodev11mo ago
Deno.serve(async (request) => {
"stuff"
});
Deno.serve(async (request) => {
"stuff"
});
ioB
ioB11mo ago
You're not returning a response, the type error is concerned with that.
mostprodev
mostprodev11mo 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
ioB11mo ago
another server is running on port 8000
mostprodev
mostprodev11mo ago
Yes.
ioB
ioB11mo 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
mostprodev11mo ago
Okay, thanks!
shawnbu
shawnbu11mo ago
I get that also. Just need to return a new Response()
More Posts
I use Deno KV for my application, and I'm planning to use Deno Deploy. Can I allow deploy to use...I use Deno KV for my application, and I'm planning to use Deno Deploy. Can I allow deploy to use KVbad resource id with node:crypto```ts function test() { const key = randomBytes(32); const iv = randomBytes(16); const cipher Close a Deno.serve() connection?Is it possible to close a Deno.serve() connection?Relative import path "preact" not prefixed with / or ./ or ../ at https://deno.land/x/fresh@1.4.Please help. ``` deno 1.36.1 (release, aarch64-apple-darwin) v8 11.6.189.12 typescript 5.1.6 ```Problems with Deno KV```ts import InputLoop from "https://deno.land/x/input@2.0.3/index.ts"; const kv = await Deno.openKFile differs only by case errorI'm getting a strange error from TypeScript. For some reason it thinks the case of my file name is Possible to have multiple http servers listening to different ports in the same module?I'm porting a service mesh platform we wrote for NodeJS over to Deno and it is based on the idea of How to have private state in embedded deno_core JsRuntime?I need to either keep a reference in rust to an object I then `delete globalThis.__context`, but I cIssues getting local environment running in VSCode and Visual Studio 2022I'm a windows user trying to contribute on an github issue, but I've run into a few blockers. Using Relative import path "ioredis" not prefixed with / or ./ or ../```ts // main.ts import Redis from "ioredis"; ``` ```json // deno.json { "imports": { "ioredis