|
1 |
| -import { Matcher, MatcherOptions } from './matches'; |
| 1 | +import { Matcher, MatcherOptions } from './matches' |
| 2 | +import { waitForOptions } from './wait-for' |
2 | 3 |
|
3 | 4 | export interface SelectorMatcherOptions extends MatcherOptions {
|
4 |
| - selector?: string; |
| 5 | + selector?: string |
5 | 6 | }
|
6 | 7 |
|
7 | 8 | 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 |
13 | 14 |
|
14 | 15 | 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[] |
20 | 21 |
|
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 |
24 | 25 |
|
25 | 26 | /**
|
26 | 27 | * query methods have a common call signature. Only the return type differs.
|
27 | 28 | */
|
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 | +> |
34 | 50 |
|
35 | 51 | 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 | +] |
42 | 58 | 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