Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Potential type improvement #7

Open
chmac opened this issue Jan 12, 2023 · 0 comments
Open

Potential type improvement #7

chmac opened this issue Jan 12, 2023 · 0 comments

Comments

@chmac
Copy link

chmac commented Jan 12, 2023

I think that there's a type mismatch. The type Event in nostr-tools has id and sig as optional. But when receiving an event from a relay, those two parameters must exist. So the type of events from a relay is, I believe, actually a Required<Event>.

I suspect that the type should be Required<NostrEvent> here:

const [events, setEvents] = useState<NostrEvent[]>([])

It looks to me as though the type of what a subscription.on('event', cb) receives (so the type of the argument passed to cb) is not specified in nostr-tools. I think that means that by changing line 136 above to Required<NostrEvent> the type would be correct.

I noticed this because when I'm trying to read the id of events in React, TypeScript complains the id could be undfined. I don't think it can be when it comes from a relay.

Apologies if this is not very clear! I'll try to explain it more clearly if this doesn't make sense.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant