Skip to content

cloneNode definition is a bit too generic #1578

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
DavidBruant opened this issue Jun 19, 2023 · 1 comment
Open

cloneNode definition is a bit too generic #1578

DavidBruant opened this issue Jun 19, 2023 · 1 comment

Comments

@DavidBruant
Copy link

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!

@HolgerJeromin
Copy link
Contributor

This is a duplicate of microsoft/TypeScript#283
It had some tests to fix in the past, but they all had problems.
Ref #842 for the newest attempt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants