From 5d25ef156ddb272e2242b0feff15623e009e1d73 Mon Sep 17 00:00:00 2001 From: Andy Edwards Date: Tue, 10 Dec 2024 14:17:39 -0600 Subject: [PATCH] fix: fix TS types --- src/index.d.ts | 282 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 268 insertions(+), 14 deletions(-) diff --git a/src/index.d.ts b/src/index.d.ts index b2a7f62..8c6b2d1 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -1,3 +1,5 @@ +/* eslint-disable @typescript-eslint/ban-types */ +/* eslint-disable @typescript-eslint/ban-ts-comment */ /// declare module 'chai-webdriverio-async' { @@ -13,24 +15,276 @@ declare module 'chai-webdriverio-async' { ): Chai.ChaiPlugin } +type ResolvedPromisedAssertion = + // @ts-ignore + unknown extends Chai.PromisedAssertion + ? PromisedAssertion + : // @ts-ignore + Chai.PromisedAssertion + +// The rest of these types are copied from chai-as-promised + +// Eventually does not have .then(), but PromisedAssertion have. +interface Eventually + extends PromisedLanguageChains, + PromisedNumericComparison, + PromisedTypeComparison { + // From chai-as-promised + become(expected: any): PromisedAssertion + fulfilled: PromisedAssertion + rejected: PromisedAssertion + rejectedWith: PromisedThrow + notify(fn: Function): PromisedAssertion + + // From chai + not: PromisedAssertion + deep: PromisedDeep + ordered: PromisedOrdered + nested: PromisedNested + any: PromisedKeyFilter + all: PromisedKeyFilter + a: PromisedTypeComparison + an: PromisedTypeComparison + include: PromisedInclude + contain: PromisedInclude + ok: PromisedAssertion + true: PromisedAssertion + false: PromisedAssertion + null: PromisedAssertion + undefined: PromisedAssertion + NaN: PromisedAssertion + exist: PromisedAssertion + empty: PromisedAssertion + arguments: PromisedAssertion + Arguments: PromisedAssertion + equal: PromisedEqual + equals: PromisedEqual + eq: PromisedEqual + eql: PromisedEqual + eqls: PromisedEqual + property: PromisedProperty + ownProperty: PromisedOwnProperty + haveOwnProperty: PromisedOwnProperty + ownPropertyDescriptor: PromisedOwnPropertyDescriptor + haveOwnPropertyDescriptor: PromisedOwnPropertyDescriptor + length: PromisedLength + lengthOf: PromisedLength + match: PromisedMatch + matches: PromisedMatch + string(string: string, message?: string): PromisedAssertion + keys: PromisedKeys + key(string: string): PromisedAssertion + throw: PromisedThrow + throws: PromisedThrow + Throw: PromisedThrow + respondTo: PromisedRespondTo + respondsTo: PromisedRespondTo + itself: PromisedAssertion + satisfy: PromisedSatisfy + satisfies: PromisedSatisfy + closeTo: PromisedCloseTo + approximately: PromisedCloseTo + members: PromisedMembers + increase: PromisedPropertyChange + increases: PromisedPropertyChange + decrease: PromisedPropertyChange + decreases: PromisedPropertyChange + change: PromisedPropertyChange + changes: PromisedPropertyChange + extensible: PromisedAssertion + sealed: PromisedAssertion + frozen: PromisedAssertion + oneOf(list: any[], message?: string): PromisedAssertion +} + +interface PromisedAssertion extends Eventually, PromiseLike {} + +interface PromisedLanguageChains { + eventually: Eventually + + // From chai + to: PromisedAssertion + be: PromisedAssertion + been: PromisedAssertion + is: PromisedAssertion + that: PromisedAssertion + which: PromisedAssertion + and: PromisedAssertion + has: PromisedAssertion + have: PromisedAssertion + with: PromisedAssertion + at: PromisedAssertion + of: PromisedAssertion + same: PromisedAssertion + but: PromisedAssertion + does: PromisedAssertion +} + +interface PromisedNumericComparison { + above: PromisedNumberComparer + gt: PromisedNumberComparer + greaterThan: PromisedNumberComparer + least: PromisedNumberComparer + gte: PromisedNumberComparer + below: PromisedNumberComparer + lt: PromisedNumberComparer + lessThan: PromisedNumberComparer + most: PromisedNumberComparer + lte: PromisedNumberComparer + within(start: number, finish: number, message?: string): PromisedAssertion +} + +interface PromisedNumberComparer { + (value: number, message?: string): PromisedAssertion +} + +interface PromisedTypeComparison { + (type: string, message?: string): PromisedAssertion + instanceof: PromisedInstanceOf + instanceOf: PromisedInstanceOf +} + +interface PromisedInstanceOf { + (constructor: Object, message?: string): PromisedAssertion +} + +interface PromisedCloseTo { + (expected: number, delta: number, message?: string): PromisedAssertion +} + +interface PromisedNested { + include: PromisedInclude + property: PromisedProperty + members: PromisedMembers +} + +interface PromisedDeep { + equal: PromisedEqual + equals: PromisedEqual + eq: PromisedEqual + include: PromisedInclude + property: PromisedProperty + members: PromisedMembers + ordered: PromisedOrdered +} + +interface PromisedOrdered { + members: PromisedMembers +} + +interface PromisedKeyFilter { + keys: PromisedKeys +} + +interface PromisedEqual { + (value: any, message?: string): PromisedAssertion +} + +interface PromisedProperty { + (name: string | symbol, value?: any, message?: string): PromisedAssertion +} + +interface PromisedOwnProperty { + (name: string | symbol, message?: string): PromisedAssertion +} + +interface PromisedOwnPropertyDescriptor { + ( + name: string | symbol, + descriptor: PropertyDescriptor, + message?: string + ): PromisedAssertion + (name: string | symbol, message?: string): PromisedAssertion +} + +interface PromisedLength + extends PromisedLanguageChains, + PromisedNumericComparison { + (length: number, message?: string): PromisedAssertion +} + +interface PromisedInclude { + (value: Object, message?: string): PromisedAssertion + (value: string, message?: string): PromisedAssertion + (value: number, message?: string): PromisedAssertion + keys: PromisedKeys + deep: PromisedDeep + ordered: PromisedOrdered + members: PromisedMembers + any: PromisedKeyFilter + all: PromisedKeyFilter +} + +interface PromisedMatch { + (regexp: RegExp | string, message?: string): PromisedAssertion +} + +interface PromisedKeys { + (...keys: string[]): PromisedAssertion + (keys: any[]): PromisedAssertion + (keys: Object): PromisedAssertion +} + +interface PromisedThrow { + (): PromisedAssertion + (expected: string | RegExp, message?: string): PromisedAssertion + ( + constructor: Error | Function, + expected?: string | RegExp, + message?: string + ): PromisedAssertion +} + +interface PromisedRespondTo { + (method: string, message?: string): PromisedAssertion +} + +interface PromisedSatisfy { + (matcher: Function, message?: string): PromisedAssertion +} + +interface PromisedMembers { + (set: any[], message?: string): PromisedAssertion +} + +interface PromisedPropertyChange { + (object: Object, property: string, message?: string): PromisedAssertion +} + declare namespace Chai { interface Assertion extends LanguageChains, NumericComparison, TypeComparison { - attribute(name: string, value?: string | RegExp): Assertion - clickable(): Assertion - count(): Assertion - count(expected: number): Assertion - existing(): Assertion - displayed(): Assertion - displayedInViewport(): Assertion - enabled(): Assertion - focused(): Assertion - selected(): Assertion - text(): Assertion - text(val: string | RegExp): Assertion - value(): Assertion - value(val: string | RegExp): Assertion + attribute(name: string, value?: string | RegExp): ResolvedPromisedAssertion + clickable(): ResolvedPromisedAssertion + count(): ResolvedPromisedAssertion + count(expected: number): ResolvedPromisedAssertion + existing(): ResolvedPromisedAssertion + displayed(): ResolvedPromisedAssertion + displayedInViewport(): ResolvedPromisedAssertion + enabled(): ResolvedPromisedAssertion + focused(): ResolvedPromisedAssertion + selected(): ResolvedPromisedAssertion + text(): ResolvedPromisedAssertion + text(val: string | RegExp): ResolvedPromisedAssertion + value(): ResolvedPromisedAssertion + value(val: string | RegExp): ResolvedPromisedAssertion + } + interface PromisedAssertion extends Eventually, PromiseLike { + attribute(name: string, value?: string | RegExp): ResolvedPromisedAssertion + clickable(): ResolvedPromisedAssertion + count(): ResolvedPromisedAssertion + count(expected: number): ResolvedPromisedAssertion + existing(): ResolvedPromisedAssertion + displayed(): ResolvedPromisedAssertion + displayedInViewport(): ResolvedPromisedAssertion + enabled(): ResolvedPromisedAssertion + focused(): ResolvedPromisedAssertion + selected(): ResolvedPromisedAssertion + text(): ResolvedPromisedAssertion + text(val: string | RegExp): ResolvedPromisedAssertion + value(): ResolvedPromisedAssertion + value(val: string | RegExp): ResolvedPromisedAssertion } }