1.2.1: Improved type system in van.d.ts
#120
Tao-VanJS
announced in
Announcements
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi fellow VanJSers,
1.2.1was just released.1.2.1is a minor release. In this release, we changedvan.d.tsto make some improvement to VanJS's type system:((dom?: Node) => ValidChildDomValue) | ((dom?: Element) => Element).(dom?: Node) => ValidChildDomValuewas the supported type for binding functions in prior versions, which means before1.2.1, the binding function for stateful binding needs to takeNode | undefinedas the input parameter. This is usually inconvenient for the primary use case where the bound DOM node is anElement, as type casting is often needed ifElement-specific methods (e.g.:querySelector) are used in the binding function.1.2.1adds another type option for the binding function -(dom?: Element) => Element, i.e.: binding function can takedom | undefinedas the input parameter as long as it only returns a DOMElement(which means this binding function is for a DOM element, where text nodes are not possible). The improved type definition can simplify the code by saving us from type castings. For instance, the binding function for theAutocompletedemo can be simplified from:to:
1.2.1added specialized return types for tags ofHTMLElementtype. With1.2.1release, things likevan.tags.header(...)will return typeHTMLElementinstead of the genericElementtype.❤️ Hope you can enjoy!
Beta Was this translation helpful? Give feedback.
All reactions