Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ This project generates alternative TypeScript standard library definitions with

- **`TypeScript/`** - Git submodule containing the official TypeScript repository for source lib files

- Note: `TypeScript/lib/lib.dom.d.ts` and `TypeScript/lib/lib.es5.d.ts` are HUGE. Never try to read the whole file at once. Always grep for specific parts.

- **`tests/`** - Type-level tests using `tsd` to verify the improved type definitions work correctly

## Essential Commands
Expand Down
8 changes: 7 additions & 1 deletion generated/lib.dom.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19836,7 +19836,7 @@ interface Node extends EventTarget {
*
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Node/parentElement)
*/
readonly parentElement: HTMLElement | null;
readonly parentElement: Element | null;
/**
* Returns the parent.
*
Expand Down Expand Up @@ -19941,6 +19941,12 @@ interface Node extends EventTarget {
readonly DOCUMENT_POSITION_CONTAINED_BY: 0x10;
readonly DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC: 0x20;
}
// /**
// * Returns the parent element.
// *
// * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Node/parentElement)
// */
// readonly parentElement: HTMLElement | null;

declare var Node: {
prototype: Node;
Expand Down
9 changes: 9 additions & 0 deletions lib/lib.dom.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,3 +255,12 @@ interface Document
interface DocumentFragment extends Node, NonElementParentNode, ParentNode {
getElementById(elementId: string): Element | null;
}

interface Node extends EventTarget {
/**
* Returns the parent element.
*
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Node/parentElement)
*/
readonly parentElement: Element | null;
}
26 changes: 26 additions & 0 deletions tests/src/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,29 @@ const test = async (url: string) => {
const svgElement: SVGElement = {} as SVGElement;
const elementOrNull: typeof element = svgElement;
}

// Node.parentElement
{
const div = document.createElement("div");
const parent = div.parentElement;
expectType<Element | null>(parent);

// Verify that the return type is not specifically HTMLElement
expectNotType<HTMLElement | null>(parent);

// Verify that SVGElement can be assigned to parentElement (without type assertion)
const svgElement: SVGElement = {} as SVGElement;
const elementOrNull: typeof parent = svgElement;

// Test with SVG elements
const svgElement2 = document.createElementNS("http://www.w3.org/2000/svg", "circle");
const svgParent = svgElement2.parentElement;
expectType<Element | null>(svgParent);

// Verify SVG elements work with parentElement
if (svgParent) {
expectType<Element>(svgParent);
// Should be able to call methods available on Element
svgParent.getAttribute("id");
}
}