mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 16:23:36 +00:00
Fix nip19 npub decoding type narrowing issue
Use negative type guard (decoded.type !== 'npub') to properly narrow the union type, allowing TypeScript to infer decoded.data as string when type is 'npub'. This fixes the type overlap error.
This commit is contained in:
1 parent
6ec4f7319c
commit
ecec383f2f
1 file changed
+3
-4
@@ -218,11 +218,10 @@ export function PullRequestDialog({
|
||||
if (pubkeyOrNpub.startsWith('npub1')) {
|
||||
try {
|
||||
const decoded = nip19.decode(pubkeyOrNpub);
|
||||
if (decoded.type === 'npub') {
|
||||
owner = decoded.data as string; // hex pubkey
|
||||
} else {
|
||||
throw new Error('Invalid npub');
|
||||
if (decoded.type !== 'npub') {
|
||||
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');
|
||||
|
||||
Reference in new issue
Block a user