-
-
Notifications
You must be signed in to change notification settings - Fork 237
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
Typescript parse5 with WTF typings #344
Comments
The AST isn't complex. The types were just badly written and poorly maintained. I rewrote them mostly from the ground up a while ago so they are much better now but still have some complexities due to the model structure here in parse5. it isn't as simple as
Unfortunately there's no obvious middle ground here. Really its like having This ultimately drills down to the fact that the source models are not branded/tagged unions. Types would be much, much nicer if that was the case. |
+1 for this post, new users using parse5 have no way of knowing that they need to explicity cast their node parents/children as the post above suggests. When I first installed parse5 and started trying to use it, I just assumed that types were either broken or required some obscure generic somewhere. It took some digging to find this post. It's not good practice to explicitly cast the types of the return of a function. This is poor type safety. With this said, it might be good to refactor some of these types to ensure that the return of a function is always strongly typed. |
hi,
WTF ?
How do you know if the child have no child (html string) ? Do you spying my files ? 👎
So I must put "as" everywhere
because parser5 say "if you are a child, you have no child", and "if you are a perent then you have no parent". Is why parse5's typings sucks.
Okay AST is complex but it's why you should allow one type and make available Parent and Child types
type Node = ParentNode | ChildNode
The text was updated successfully, but these errors were encountered: