TypeScript-DOM-lib-generator icon indicating copy to clipboard operation
TypeScript-DOM-lib-generator copied to clipboard

[Web API type definition issue] Node.parentElement has wrong type

Open trusktr opened this issue 9 months ago • 3 comments

Summary

Node.parentElement has type HTMLElement | null but it should be Element | null

Expected vs. Actual Behavior

Expected: node.parentElement type to be Element | null Actual: HTMLElement | null

Playground Link

https://www.typescriptlang.org/play/?#code/MYewdgzgLgBKZQIYEswFMBOMC8MAmIwArgLZoIB0wGaiUaAogDZpkIAUA5HsgG6cBKAFDwkqTBVToMACQAqAWQAyOGJwA8EXgHMAfOr3qA9IaNa9nISPDQY21aJTSKAM2QZozVuSgBhABbITHgAhK7unixsfoHBMIgQMADKAGoA4mle0VbwECAsFEwg2uzaFAAOiDQIWT4wqNCIYMBoIC7J6bUIAjBGRjBQGERoMDk2sNoATKplldVQXbAJHZlRPmOQ+WiFxaXTDUjNre2pq97dvf2ITHkDQ2hCQA

Browser Support

  • [x] This API is supported in at least two major browser engines (not two Chromium-based browsers).

Have Tried The Latest Releases

  • [x] This issue applies to the latest release of TypeScript.
  • [x] This issue applies to the latest release of @types/web.

Additional Context

Proof: run the example in the playground.

Similar to:

  • https://github.com/microsoft/TypeScript-DOM-lib-generator/issues/2020

trusktr avatar May 15 '25 06:05 trusktr

Typescript does not want to be precise but also usable. Having errors on code like this would be annoying, too

const div = document.createElement('div')
console.log(div.parentElement?.style.display)

HolgerJeromin avatar May 15 '25 07:05 HolgerJeromin

Also dupe of #1706 (which is again dupe of #1151)

saschanaz avatar May 15 '25 21:05 saschanaz

(which is again dupe of #1151)

which was opened by .... trusktr himself :-)

HolgerJeromin avatar May 16 '25 07:05 HolgerJeromin