diff --git a/src/baseWrapper.ts b/src/baseWrapper.ts index fab7027ef..743f35d2b 100644 --- a/src/baseWrapper.ts +++ b/src/baseWrapper.ts @@ -197,8 +197,8 @@ export default abstract class BaseWrapper } 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 = {} if (isElement(this.element)) { const attributes = Array.from(this.element.attributes) diff --git a/src/interfaces/wrapperLike.ts b/src/interfaces/wrapperLike.ts index 722256ca3..59bdfd765 100644 --- a/src/interfaces/wrapperLike.ts +++ b/src/interfaces/wrapperLike.ts @@ -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 diff --git a/test-dts/wrapper.d-test.ts b/test-dts/wrapper.d-test.ts index 07fb7d527..03d3de6fb 100644 --- a/test-dts/wrapper.d-test.ts +++ b/test-dts/wrapper.d-test.ts @@ -64,7 +64,8 @@ expectType(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(byClass.element) // attributes expectType<{ [key: string]: string }>(wrapper.attributes()) -expectType(wrapper.attributes('key')) +expectType(wrapper.attributes('key')) expectType<{ [key: string]: string }>(domWrapper.attributes()) -expectType(domWrapper.attributes('key')) +expectType(domWrapper.attributes('key')) // classes expectType>(wrapper.classes())