Skip to content

Element.closest should return specific types for tag selectors #17550

Closed
@thw0rted

Description

@thw0rted

TypeScript Version: 2.4.0

Code

let a = document.querySelectorAll("a");
let div = a.closest("div");

Expected behavior:

a is an HTMLAnchorElement, and div is an HTMLDivElement.

Actual behavior:

el2 is actually an Element because Element.closest always returns an Element. This was fixed for querySelector in #8114 and the same behavior should be applied to closest.

Metadata

Metadata

Assignees

Labels

Domain: lib.d.tsThe issue relates to the different libraries shipped with TypeScriptFixedA PR has been merged for this issueHelp WantedYou can do thisSuggestionAn idea for TypeScript

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions