Skip to content

Commit 62e8c8f

Browse files
committed
chore: add overloads for attributes method
1 parent 112f29a commit 62e8c8f

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

src/dom-wrapper.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@ export class DOMWrapper<ElementType extends Element> {
1818
return Array.from(classes)
1919
}
2020

21-
attributes(key?: string) {
21+
attributes(): { [key: string]: string }
22+
attributes(key: string): string
23+
attributes(key?: string): { [key: string]: string } | string {
2224
const attributes = this.element.attributes
23-
const attributeMap = {}
25+
const attributeMap: { [key: string]: string } = {}
2426
for (let i = 0; i < attributes.length; i++) {
25-
const att = attributes.item(i)
27+
const att = attributes.item(i)!
2628
attributeMap[att.localName] = att.value
2729
}
2830

src/vue-wrapper.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ export class VueWrapper<T extends ComponentPublicInstance> {
5454
return new DOMWrapper(this.element).classes(className)
5555
}
5656

57-
attributes(key?: string) {
57+
attributes(): { [key: string]: string }
58+
attributes(key: string): string
59+
attributes(key?: string): { [key: string]: string } | string {
5860
return new DOMWrapper(this.element).attributes(key)
5961
}
6062

test-dts/wrapper.d-test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,9 @@ expectType<SVGLineElement>(line.element)
8686
// string selector
8787
byClass = domWrapper.get('.todo')
8888
expectType<Element>(byClass.element)
89+
90+
// attributes
91+
expectType<{ [key: string]: string }>(wrapper.attributes())
92+
expectType<string>(wrapper.attributes('key'))
93+
expectType<{ [key: string]: string }>(domWrapper.attributes())
94+
expectType<string>(domWrapper.attributes('key'))

0 commit comments

Comments
 (0)