mostprodev
Deno Types
What is the Deno.ServeHandler type?
Does it not support async?
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.
12 replies
Problems with Deno KV
import InputLoop from "https://deno.land/x/input@2.0.3/index.ts";
const kv = await Deno.openKv();
const input = new InputLoop();
let name;
let age;
let profession;
let id;
while (true) {
console.log("");
console.log("DENO KV DEMO");
console.log("> 0: Read Database");
console.log("> 1: Create/Edit User");
console.log("> 2: Delete User");
console.log("> 3: Exit");
const choice = await input.question("Input: ", false);
switch (choice) {
case "0":
for (const i in kv.list({ prefix: ["users"] })) {
console.log(i);
}
break;
case "1":
name = await input.question("Name: ", false);
if (!name) {
console.log("Invalid Input!");
break;
}
age = await input.question("Age: ", false);
profession = await input.question("Profession: ", false);
id = await input.question("Id: ", false);
await kv.set(["users", name], { age, profession, id });
break;
case "2":
name = await input.question("Name: ", false);
if (!name) {
console.log("Invalid Input!");
break;
}
kv.delete(["users", name]);
break;
case "3":
Deno.exit();
break;
default:
console.log("Invalid Input!");
}
}
import InputLoop from "https://deno.land/x/input@2.0.3/index.ts";
const kv = await Deno.openKv();
const input = new InputLoop();
let name;
let age;
let profession;
let id;
while (true) {
console.log("");
console.log("DENO KV DEMO");
console.log("> 0: Read Database");
console.log("> 1: Create/Edit User");
console.log("> 2: Delete User");
console.log("> 3: Exit");
const choice = await input.question("Input: ", false);
switch (choice) {
case "0":
for (const i in kv.list({ prefix: ["users"] })) {
console.log(i);
}
break;
case "1":
name = await input.question("Name: ", false);
if (!name) {
console.log("Invalid Input!");
break;
}
age = await input.question("Age: ", false);
profession = await input.question("Profession: ", false);
id = await input.question("Id: ", false);
await kv.set(["users", name], { age, profession, id });
break;
case "2":
name = await input.question("Name: ", false);
if (!name) {
console.log("Invalid Input!");
break;
}
kv.delete(["users", name]);
break;
case "3":
Deno.exit();
break;
default:
console.log("Invalid Input!");
}
}
6 replies