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

Support type guards for the output of the parser #99

Merged
merged 2 commits into from
Jan 25, 2025

Conversation

wrnrlr
Copy link
Contributor

@wrnrlr wrnrlr commented Jan 25, 2025

I've added support for type guards on the output of the parser by annotating the result of the parser as a discriminating union.

This will help typescript to infer the type of the Reader when checking the SaxEventType:

for await (const [event, detail] of parser.parse(reader)) {
  if (event === SaxEventType.Attribute) {
    detail.name
  } else if (event === SaxEventType.OpenTag) {
    detail.attributes
  }
}

@justinwilaby
Copy link
Owner

Nice! This is an easy approval.

Copy link
Owner

@justinwilaby justinwilaby left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much better! Thank you for putting this together.

@justinwilaby justinwilaby merged commit ba08def into justinwilaby:master Jan 25, 2025
2 checks passed
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

Successfully merging this pull request may close these issues.

2 participants