Skip to content

Commit 303e08f

Browse files
committed
Add regression test
1 parent c0e0c1c commit 303e08f

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// @strict: true
2+
3+
// Repro from #24233
4+
5+
declare global {
6+
interface ElementTagNameMap {
7+
[index: number]: HTMLElement
8+
}
9+
10+
interface HTMLElement {
11+
[index: number]: HTMLElement;
12+
}
13+
}
14+
15+
export function assertIsElement(node: Node | null): node is Element {
16+
let nodeType = node === null ? null : node.nodeType;
17+
return nodeType === 1;
18+
}
19+
20+
export function assertNodeTagName<
21+
T extends keyof ElementTagNameMap,
22+
U extends ElementTagNameMap[T]>(node: Node | null, tagName: T): node is U {
23+
if (assertIsElement(node)) {
24+
const nodeTagName = node.tagName.toLowerCase();
25+
return nodeTagName === tagName;
26+
}
27+
return false;
28+
}
29+
30+
export function assertNodeProperty<
31+
T extends keyof ElementTagNameMap,
32+
P extends keyof ElementTagNameMap[T],
33+
V extends HTMLElementTagNameMap[T][P]>(node: Node | null, tagName: T, prop: P, value: V) {
34+
if (assertNodeTagName(node, tagName)) {
35+
node[prop];
36+
}
37+
}

0 commit comments

Comments
 (0)