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
-
Hi fellow VanJSers,
1.2.1
was just released.1.2.1
is a minor release. In this release, we changedvan.d.ts
to make some improvement to VanJS's type system:((dom?: Node) => ValidChildDomValue) | ((dom?: Element) => Element)
.(dom?: Node) => ValidChildDomValue
was the supported type for binding functions in prior versions, which means before1.2.1
, the binding function for stateful binding needs to takeNode | undefined
as 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.1
adds another type option for the binding function -(dom?: Element) => Element
, i.e.: binding function can takedom | undefined
as 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 theAutocomplete
demo can be simplified from:to:
1.2.1
added specialized return types for tags ofHTMLElement
type. With1.2.1
release, things likevan.tags.header(...)
will return typeHTMLElement
instead of the genericElement
type.❤️ Hope you can enjoy!
Beta Was this translation helpful? Give feedback.
All reactions