From 2f79762d03a92befaf11fa6a0e918233f904b0eb Mon Sep 17 00:00:00 2001 From: Tomasz Pluskiewicz Date: Tue, 18 May 2021 21:51:53 +0200 Subject: [PATCH] feat(types): generic arg for Predicate I propose a generic argument added to the matchers, so that the callback can be typed if desired, thus making the usage easier. Using the types from DT, I could write: ```ts expect(objects).to.containAll(obj => obj.selectedEditor?.value === dash.TextFieldEditor.value) ``` having `obj` be of the given type. --- src/index.d.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/index.d.ts b/src/index.d.ts index 93a1cd0..a3d4b93 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -3,20 +3,20 @@ declare global { namespace Chai { interface Assertion extends LanguageChains, NumericComparison, TypeComparison { - containAll(predicate: Predicate): Assertion; - containOne(predicate: Predicate): Assertion; - containExactlyOne(predicate: Predicate): Assertion; + containAll(predicate: Predicate): Assertion; + containOne(predicate: Predicate): Assertion; + containExactlyOne(predicate: Predicate): Assertion; } interface Assert { - containAll(val: any[], predicate: Predicate, msg?: string): void; - containOne(val: any[], predicate: Predicate, msg?: string): void; - containExactlyOne(val: any[], predicate: Predicate, msg?: string): void; + containAll(val: T[], predicate: Predicate, msg?: string): void; + containOne(val: T[], predicate: Predicate, msg?: string): void; + containExactlyOne(val: T[], predicate: Predicate, msg?: string): void; } } } -type Predicate = (item: any) => boolean; +type Predicate = (item: T) => boolean; declare const chaiQuantifiers: Chai.ChaiPlugin; export = chaiQuantifiers;