Skip to content

querySelector return type could be more specific for single-element selectors #8114

Closed
microsoft/TypeScript-DOM-lib-generator
#102
@jelbourn

Description

@jelbourn

The return types for querySelector and querySelectorAll (in the lib.es6.d.ts) could provide more specific return type information when the selector a single element selector for a known element type.

I.e., right now the types are

interface NodeSelector {
    querySelector(selectors: string): Element;
    querySelectorAll(selectors: string): NodeListOf<Element>;
}

But it could be expanded in the style of getElementsByTagName:

interface NodeSelector {
    querySelector(selectors: "a"): HTMLAnchorElement;
    querySelector(selectors: "abbr"): HTMLPhraseElement;
    ...
    querySelector(selectors: string): Element;
}

It's a minor convenience, but does eliminate the occasional typecast.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FixedA 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