Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(type): add undefined type to attributes() for missing key #1398

Merged
merged 1 commit into from
Apr 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/baseWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/interfaces/wrapperLike.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions test-dts/wrapper.d-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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())
Expand Down