Update the return of the closest function to ensure that we return either a HTMLElement or null.
As the MDN spec for the .closest function states, the return type is 'The closest ancestor Element or itself, which matches the selectors. If there are no such element, null'
This means it should be an actual Element type and not a node. This solves a wider issue with TS that prevents users from chaining querySelector and calls to closest.
This provides a much more native behaviour akin to what is actually experienced within the browser environment.
Update the return of the closest function to ensure that we return either a HTMLElement or null.
As the MDN spec for the .closest function states, the return type is 'The closest ancestor Element or itself, which matches the selectors. If there are no such element, null'
This means it should be an actual Element type and not a node. This solves a wider issue with TS that prevents users from chaining
querySelector
and calls toclosest
.This provides a much more native behaviour akin to what is actually experienced within the browser environment.