From c037bd13764f2f60a82fa868e315b4c2f900107c Mon Sep 17 00:00:00 2001 From: "shakespeare.diy" Date: Wed, 15 Oct 2025 01:33:41 -0500 Subject: [PATCH] Fix nip19 npub decoding with proper positive type guard Use positive type guard (decoded.type === 'npub' && typeof decoded.data === 'string') to properly narrow the union type. TypeScript requires both conditions to infer the correct type for decoded.data when dealing with discriminated unions. --- src/components/git/PullRequestDialog.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/components/git/PullRequestDialog.tsx b/src/components/git/PullRequestDialog.tsx index 6d5db402..babab13e 100644 --- a/src/components/git/PullRequestDialog.tsx +++ b/src/components/git/PullRequestDialog.tsx @@ -218,10 +218,12 @@ export function PullRequestDialog({ if (pubkeyOrNpub.startsWith('npub1')) { try { const decoded = nip19.decode(pubkeyOrNpub); - if (decoded.type !== 'npub') { + // Type guard: ensure we have an npub + if (decoded.type === 'npub' && typeof decoded.data === 'string') { + owner = decoded.data; // hex pubkey + } else { throw new Error('Expected npub but got ' + decoded.type); } - owner = decoded.data; // hex pubkey } catch (err) { console.error('Failed to decode npub:', err); setError('Invalid npub in Nostr URL');