Add regression test

This commit is contained in:
Anders Hejlsberg 2018-07-21 12:31:24 -07:00
parent c0e0c1c2f3
commit 303e08fc4f

View File

@ -0,0 +1,37 @@
// @strict: true
// Repro from #24233
declare global {
interface ElementTagNameMap {
[index: number]: HTMLElement
}
interface HTMLElement {
[index: number]: HTMLElement;
}
}
export function assertIsElement(node: Node | null): node is Element {
let nodeType = node === null ? null : node.nodeType;
return nodeType === 1;
}
export function assertNodeTagName<
T extends keyof ElementTagNameMap,
U extends ElementTagNameMap[T]>(node: Node | null, tagName: T): node is U {
if (assertIsElement(node)) {
const nodeTagName = node.tagName.toLowerCase();
return nodeTagName === tagName;
}
return false;
}
export function assertNodeProperty<
T extends keyof ElementTagNameMap,
P extends keyof ElementTagNameMap[T],
V extends HTMLElementTagNameMap[T][P]>(node: Node | null, tagName: T, prop: P, value: V) {
if (assertNodeTagName(node, tagName)) {
node[prop];
}
}