Skip to content

Commit 76a6886

Browse files
committed
fix(TS): add fourth param to build findAllBy and findBy queries
1 parent dcad11b commit 76a6886

File tree

1 file changed

+47
-31
lines changed

1 file changed

+47
-31
lines changed

types/query-helpers.d.ts

Lines changed: 47 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,62 @@
1-
import { Matcher, MatcherOptions } from './matches';
1+
import { Matcher, MatcherOptions } from './matches'
2+
import { waitForOptions } from './wait-for'
23

34
export interface SelectorMatcherOptions extends MatcherOptions {
4-
selector?: string;
5+
selector?: string
56
}
67

78
export type QueryByAttribute = (
8-
attribute: string,
9-
container: HTMLElement,
10-
id: Matcher,
11-
options?: MatcherOptions,
12-
) => HTMLElement | null;
9+
attribute: string,
10+
container: HTMLElement,
11+
id: Matcher,
12+
options?: MatcherOptions,
13+
) => HTMLElement | null
1314

1415
export type AllByAttribute = (
15-
attribute: string,
16-
container: HTMLElement,
17-
id: Matcher,
18-
options?: MatcherOptions,
19-
) => HTMLElement[];
16+
attribute: string,
17+
container: HTMLElement,
18+
id: Matcher,
19+
options?: MatcherOptions,
20+
) => HTMLElement[]
2021

21-
export const queryByAttribute: QueryByAttribute;
22-
export const queryAllByAttribute: AllByAttribute;
23-
export function getElementError(message: string, container: HTMLElement): Error;
22+
export const queryByAttribute: QueryByAttribute
23+
export const queryAllByAttribute: AllByAttribute
24+
export function getElementError(message: string, container: HTMLElement): Error
2425

2526
/**
2627
* query methods have a common call signature. Only the return type differs.
2728
*/
28-
export type QueryMethod<Arguments extends any[], Return> = (container: HTMLElement, ...args: Arguments) => Return;
29-
export type QueryBy<Arguments extends any[]> = QueryMethod<Arguments, HTMLElement | null>;
30-
export type GetAllBy<Arguments extends any[]> = QueryMethod<Arguments, HTMLElement[]>;
31-
export type FindAllBy<Arguments extends any[]> = QueryMethod<Arguments, Promise<HTMLElement[]>>;
32-
export type GetBy<Arguments extends any[]> = QueryMethod<Arguments, HTMLElement>;
33-
export type FindBy<Arguments extends any[]> = QueryMethod<Arguments, Promise<HTMLElement>>;
29+
export type QueryMethod<Arguments extends any[], Return> = (
30+
container: HTMLElement,
31+
...args: Arguments
32+
) => Return
33+
export type QueryBy<Arguments extends any[]> = QueryMethod<
34+
Arguments,
35+
HTMLElement | null
36+
>
37+
export type GetAllBy<Arguments extends any[]> = QueryMethod<
38+
Arguments,
39+
HTMLElement[]
40+
>
41+
export type FindAllBy<Arguments extends any[]> = QueryMethod<
42+
[Arguments[0], Arguments[1], waitForOptions],
43+
Promise<HTMLElement[]>
44+
>
45+
export type GetBy<Arguments extends any[]> = QueryMethod<Arguments, HTMLElement>
46+
export type FindBy<Arguments extends any[]> = QueryMethod<
47+
[Arguments[0], Arguments[1], waitForOptions],
48+
Promise<HTMLElement>
49+
>
3450

3551
export type BuiltQueryMethods<Arguments extends any[]> = [
36-
QueryBy<Arguments>,
37-
GetAllBy<Arguments>,
38-
GetBy<Arguments>,
39-
FindAllBy<Arguments>,
40-
FindBy<Arguments>
41-
];
52+
QueryBy<Arguments>,
53+
GetAllBy<Arguments>,
54+
GetBy<Arguments>,
55+
FindAllBy<Arguments>,
56+
FindBy<Arguments>,
57+
]
4258
export function buildQueries<Arguments extends any[]>(
43-
queryByAll: GetAllBy<Arguments>,
44-
getMultipleError: (container: HTMLElement, ...args: Arguments) => string,
45-
getMissingError: (container: HTMLElement, ...args: Arguments) => string,
46-
): BuiltQueryMethods<Arguments>;
59+
queryByAll: GetAllBy<Arguments>,
60+
getMultipleError: (container: HTMLElement, ...args: Arguments) => string,
61+
getMissingError: (container: HTMLElement, ...args: Arguments) => string,
62+
): BuiltQueryMethods<Arguments>

0 commit comments

Comments
 (0)