D
Deno

help

Deno KV Type Error

Mmostprodev8/25/2023
When I run await (await kv.get<typeThing>(["example"])).id (the value is an object), it returns a type error because it is a maybe type thing. The error:
Property 'id' does not exist on type 'KvEntryMaybe<typeThing>'.
Property 'id' does not exist on type '{ key: KvKey; value: null; versionstamp: null; }'.deno-ts(2339)
Property 'id' does not exist on type 'KvEntryMaybe<typeThing>'.
Property 'id' does not exist on type '{ key: KvKey; value: null; versionstamp: null; }'.deno-ts(2339)
Perhaps the problem changed. The top is the problem. Although I check that await kv.get<typeThing>(["example"]) != null, with an if statement, it still does not get rid of the error.
ABAltair 680b8/26/2023
let result = await kv.get<typeThing>(["example"])
// get returns a KvEntryMaybe object = {key, value, versionstamp}
// If (result.value === null) => `key was not found`
if {result.value) console.log(result.value.id);
// no error will be thrown! your error was that 'id' does not exist // on the `KvEntryMaybe` returned by the `get` method.
let result = await kv.get<typeThing>(["example"])
// get returns a KvEntryMaybe object = {key, value, versionstamp}
// If (result.value === null) => `key was not found`
if {result.value) console.log(result.value.id);
// no error will be thrown! your error was that 'id' does not exist // on the `KvEntryMaybe` returned by the `get` method.
Mmostprodev8/26/2023
Cool. This is not different from != null.
ABAltair 680b8/26/2023
You could do (result !== null) Be aware that the object returned by the promise KvEntryMaybe = {key, value, versionstamp}, will always return the key, but if not found, both the value, and the timestamp will be null.
Mmostprodev8/26/2023
Oh, okay. Thanks.
ABAltair 680b8/26/2023
Also, as someone could insert a row with the value set to null, it might be best to check the versionstamp for null, rather than the value. Be aware that some folks might just use the multipart key as both key and data, and just put null in the value field.
Mmostprodev8/26/2023
This doesn't work.
'user_data.value' is possibly 'null'.deno-ts(18047)
(property) value: User | null
'user_data.value' is possibly 'null'.deno-ts(18047)
(property) value: User | null
Even when doing the if statement + the result declaration. Nvm.

Looking for more? Join the community!

Recommended Posts
How to improve seo ?https://deno.land/x/blog My question is when you use tool like this that work with md, how can i do Hashbang with TS file (without .ts extension)Hi y'all, I have a few convenience scripts written in Typescript for Deno that all have a wrapper scAstro + Deno - Remote ImportsFirst of all thanks a lot for the nice template, it looks great !! I followed the guide posted hereDebugging test in VSCode always breaks on line 54 of colors.tsWhen debugging tests in VSCode the debugger always breaks on line 54 of colors.ts. This behavior is Building from `src` offline?Hey guys! I'm new to Deno (and web dev as well to be honest), so could you help me here please. I'Any plan to fix Deno.listenTls() timing out a WebSocket connection?Any plan to fix Deno.listenTls() timing out a WebSocket connection? ``` {code: 1001, reason: 'No rePlaying sound from fileHow can i play the sound from a local file using deno?Deno with the --inspect-wait arg doesn't expose /json/protocol - should it?I'm testing out connecting to a Deno process via the v8 inspector protocol: https://deno.land/manual`deno test` and VSCode test runner are failing to run all test filesIn my Fresh projects, I'm trying to run all my tests with a single command. This used to not be an iHelp on Deno deploy that failsHi all, I'm having an issue on Deno deploy that states as follow: 'Error: The deployment failed: MoDeno console.log() all items of arrayHey how can I enable all of the output, so that Deno does not cut of items?Hey! i can't to download denoHEY~ I am a Taiwanese people so my English not good but I have a question My PowerShell show this Closing a fileHow do I close a file after opening and streaming it? My handler function code is as follows: ``` repuppeteer makes script to hang for a while at the endI am using `npm:puppeteer` in my script. Everything is working fine. But often the script hangs at tIn Fresh, how do I return a JSON response in a middleware?In Fresh, how do I return a JSON response in a middleware?get length for KV list via prefix?Is there a fast way to get just the count of items for a prefix?Property 'params' does not exist on type 'Context<State, Record<string, any>> ... what to do?I want to access params in oak, but typescript complains. What can I do about that? Thanks.What is the std library for making a guessing game like shown in rust?```rust use std::io; fn main() { println!("Guess the number!"); println!("Please input youData must be valid JSONA simple project, after successful deployment, reports an error "Data must be valid JSON".FFI deno_bindgen, how to see build logs?Hi, using deno_bindgen for rust, is there anyway i can view the build logs? --verbose or -v do not s