-
Notifications
You must be signed in to change notification settings - Fork 11
/
shim.test.ts
50 lines (41 loc) · 1.75 KB
/
shim.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import './shim.js'
import type { Equal, Expect } from '@type-challenges/utils'
const htmlEl = document.querySelector(
'.container > #sign-up-form > div#notice, span.tip',
)
type TestEl = Expect<
Equal<typeof htmlEl, HTMLDivElement | HTMLSpanElement | null>
>
declare let selector: string
const link = document.querySelector<HTMLAnchorElement>(selector)
type TestLink = Expect<Equal<typeof link, HTMLAnchorElement | null>>
// @ts-expect-error
const a1: HTMLAnchorElement | null = document.querySelector('div')
// @ts-expect-error
const a2: HTMLAnchorElement | null = document.querySelector('div#app')
const results: Array<HTMLAnchorElement | null> = []
// @ts-expect-error
results.push(document.querySelector('div'))
// @ts-expect-error
results.push(document.querySelector('div#app'))
const closest = htmlEl!.closest('button.btn-confirm, a.link')
type TestClosest = Expect<
Equal<typeof closest, HTMLButtonElement | HTMLAnchorElement | null>
>
const unknownEl = document.querySelector('unknown')
type TestElement = Expect<Equal<typeof unknownEl, Element | null>>
declare let btn: HTMLButtonElement
const elementOfBtn = btn.querySelector('unknown')
type TestElementOfBtn = Expect<Equal<typeof elementOfBtn, Element | null>>
declare let element: Element
const elementOfElement = element.querySelector('unknown')
type TestElementOfElement = Expect<
Equal<typeof elementOfElement, Element | null>
>
declare let documentFragment: DocumentFragment
document.querySelector<Element>('my-web-component')
document.querySelectorAll<Element>('my-web-component')
element.querySelector<Element>('my-web-component')
element.querySelectorAll<Element>('my-web-component')
documentFragment.querySelector<Element>('my-web-component')
documentFragment.querySelectorAll<Element>('my-web-component')