Skip to content

Commit

Permalink
fix(type): add undefined type to attributes() for missing key (#1398)
Browse files Browse the repository at this point in the history
  • Loading branch information
freakzlike authored Apr 5, 2022
1 parent 794b192 commit 5666ca4
Showing 3 changed files with 8 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/baseWrapper.ts
Original file line number Diff line number Diff line change
@@ -197,8 +197,8 @@ export default abstract class BaseWrapper<ElementType extends Node>
}

attributes(): { [key: string]: string }
attributes(key: string): string
attributes(key?: string): { [key: string]: string } | string {
attributes(key: string): string | undefined
attributes(key?: string): { [key: string]: string } | string | undefined {
const attributeMap: Record<string, string> = {}
if (isElement(this.element)) {
const attributes = Array.from(this.element.attributes)
4 changes: 2 additions & 2 deletions src/interfaces/wrapperLike.ts
Original file line number Diff line number Diff line change
@@ -99,8 +99,8 @@ export default interface WrapperLike {
classes(className?: string): string[] | boolean

attributes(): { [key: string]: string }
attributes(key: string): string
attributes(key?: string): { [key: string]: string } | string
attributes(key: string): string | undefined
attributes(key?: string): { [key: string]: string } | string | undefined

text(): string
exists(): boolean
7 changes: 4 additions & 3 deletions test-dts/wrapper.d-test.ts
Original file line number Diff line number Diff line change
@@ -64,7 +64,8 @@ expectType<Element | undefined>(byClassArray[0].element)
// emitted
// event name
let incrementEvent = wrapper.emitted<{ count: number }>('increment')
expectType<{ count: number }>(incrementEvent[0])
expectType<{ count: number }[] | undefined>(incrementEvent)
expectType<{ count: number }>(incrementEvent![0])

// without event name
let allEvents = wrapper.emitted()
@@ -98,9 +99,9 @@ expectType<Element>(byClass.element)

// attributes
expectType<{ [key: string]: string }>(wrapper.attributes())
expectType<string>(wrapper.attributes('key'))
expectType<string | undefined>(wrapper.attributes('key'))
expectType<{ [key: string]: string }>(domWrapper.attributes())
expectType<string>(domWrapper.attributes('key'))
expectType<string | undefined>(domWrapper.attributes('key'))

// classes
expectType<Array<string>>(wrapper.classes())

0 comments on commit 5666ca4

Please sign in to comment.