whaleyW
Denoβ€’5mo agoβ€’
2 replies
whaley

Deno KV Type narrowing issue

import { createDiscordOAuthConfig, createHelpers } from '@deno/kv-oauth'
import { env } from '../../../env.ts'

// Discord OAuth configuration for bot authorization
// This authorizes the bot to join and operate in Discord servers
const oauthConfig = createDiscordOAuthConfig({
  redirectUri: [env.BASE_URL, '/oauth/discord/callback'].join(''),
  scope: ['bot', 'applications.commands'], // Bot permissions
})

export const discordOAuthHelpers = createHelpers(oauthConfig)

export { oauthConfig as discordOAuthConfig }


I'm setting up a discord bot for my application, so I can run bot automations when doing actions in the app. Some organizations will have bots, others won't, so it's critical that the session ID in deno kv oauth is string | undefined so I can guard correctly, right?

I've investigated the deno kv and deno kv oauth 2 source code and I'm seeing explicit types that don't align with the actual return types. I'm not sure if I'm just missing some critical info or if this is a TypeScript LSP bug, or what's going on... Can someone clue me in?

I might just be totally off-base and doing things totally wrong here.
image.png
image.png
Was this page helpful?