Skip to content

cloneNode definition is a bit too generic #1578

Open
@DavidBruant

Description

@DavidBruant

Hi, this is my first issue here so i'm trying my best and hope it'll work
and if it doesn't, let me know and i'll try to improve my feedback

I'm sharing this example:

const el = document.createElement('input')

const el2 = el.cloneNode()

el2.querySelector('')

In playground: https://www.typescriptlang.org/play?#code/MYewdgzgLgBApgGxgXhgExMArgWzmKAOmACc4BDKOAUQTjwIAoByASzAAcspmBKAKH6hIsRACYU8BMQTg4AORBo4jAf3GEAjljgkAngGVEcYFBAkWfIA

In this example, the TypeScript parser sends an error: "Property 'querySelector' does not exist on type 'Node'."

However, in the real DOM (at least in Firefox, but i'm pretty sure in other browsers too), el2 is an HTMLInputElement (like el) and this property does exist on it

The type I see in the generated version of the dom library is:
cloneNode(deep?: boolean): Node;

and i feel it probably should be something like:
cloneNode<T extends Node>(deep?: boolean): T;

or maybe something with the type of this, i'm not super-familiar yet with this part of TypeScript

I haven't taken the time to understand how this repo works, so i'm not sure how to transform this idea into a PR, but in any case, at this point, i'm more interested in understanding whether you agree on the problem i'm describing here

Thanks for your time reading this issue!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions