Skip to content

Commit bce30bf

Browse files
committed
refactor: remove usage of String
1 parent 18dcf4d commit bce30bf

File tree

2 files changed

+50
-30
lines changed

2 files changed

+50
-30
lines changed

types/matches.d.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
1-
import { ARIARole } from 'aria-query'
2-
31
export type MatcherFunction = (content: string, element: HTMLElement) => boolean
42
export type Matcher = string | RegExp | MatcherFunction
53

6-
// important to use String here
7-
// this gives us intellisense but it can also accept values
8-
// that are not included in the union types
9-
// tslint:disable-next-line:ban-types
10-
export type ByRoleMatcher = ARIARole | String | RegExp | MatcherFunction
11-
124
export type NormalizerFn = (text: string) => string
135

146
export interface MatcherOptions {

types/queries.d.ts

Lines changed: 50 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { Matcher, MatcherOptions, ByRoleMatcher } from './matches'
1+
import { Matcher, MatcherOptions } from './matches'
22
import { SelectorMatcherOptions } from './query-helpers'
33
import { waitForOptions } from './wait-for'
4+
import { ARIARole } from 'aria-query'
45

56
export type QueryByBoundAttribute = (
67
container: HTMLElement,
@@ -92,37 +93,64 @@ export interface ByRoleOptions extends MatcherOptions {
9293
| ((accessibleName: string, element: Element) => boolean)
9394
}
9495

95-
export type AllByRole = (
96+
export declare function AllByRole(
9697
container: HTMLElement,
97-
role: ByRoleMatcher,
98+
role: Matcher,
9899
options?: ByRoleOptions,
99-
) => HTMLElement[]
100+
): HTMLElement[]
101+
export declare function AllByRole(
102+
container: HTMLElement,
103+
role: ARIARole,
104+
options?: ByRoleOptions,
105+
): HTMLElement[]
100106

101-
export type GetByRole = (
107+
export declare function GetByRole(
102108
container: HTMLElement,
103-
role: ByRoleMatcher,
109+
role: Matcher,
104110
options?: ByRoleOptions,
105-
) => HTMLElement
111+
): HTMLElement
112+
export declare function GetByRole(
113+
container: HTMLElement,
114+
role: ARIARole,
115+
options?: ByRoleOptions,
116+
): HTMLElement
106117

107-
export type QueryByRole = (
118+
export declare function QueryByRole(
108119
container: HTMLElement,
109-
role: ByRoleMatcher,
120+
role: Matcher | ByRoleOptions,
110121
options?: ByRoleOptions,
111-
) => HTMLElement | null
122+
): HTMLElement | null
123+
export declare function QueryByRole(
124+
container: HTMLElement,
125+
role: ARIARole,
126+
options?: ByRoleOptions,
127+
): HTMLElement | null
112128

113-
export type FindByRole = (
129+
export declare function FindByRole(
114130
container: HTMLElement,
115-
role: ByRoleMatcher,
131+
role: Matcher,
116132
options?: ByRoleOptions,
117133
waitForElementOptions?: waitForOptions,
118-
) => Promise<HTMLElement>
134+
): Promise<HTMLElement>
135+
export declare function FindByRole(
136+
container: HTMLElement,
137+
role: ARIARole,
138+
options?: ByRoleOptions,
139+
waitForElementOptions?: waitForOptions,
140+
): Promise<HTMLElement>
119141

120-
export type FindAllByRole = (
142+
export declare function FindAllByRole(
121143
container: HTMLElement,
122-
role: ByRoleMatcher,
144+
role: Matcher,
123145
options?: ByRoleOptions,
124146
waitForElementOptions?: waitForOptions,
125-
) => Promise<HTMLElement[]>
147+
): Promise<HTMLElement[]>
148+
export declare function FindAllByRole(
149+
container: HTMLElement,
150+
role: Matcher,
151+
options?: ByRoleOptions,
152+
waitForElementOptions?: waitForOptions,
153+
): Promise<HTMLElement[]>
126154

127155
export const getByLabelText: GetByText
128156
export const getAllByLabelText: AllByText
@@ -160,12 +188,12 @@ export const queryByDisplayValue: QueryByBoundAttribute
160188
export const queryAllByDisplayValue: AllByBoundAttribute
161189
export const findByDisplayValue: FindByBoundAttribute
162190
export const findAllByDisplayValue: FindAllByBoundAttribute
163-
export const getByRole: GetByRole
164-
export const getAllByRole: AllByRole
165-
export const queryByRole: QueryByRole
166-
export const queryAllByRole: AllByRole
167-
export const findByRole: FindByRole
168-
export const findAllByRole: FindAllByRole
191+
export const getByRole: typeof GetByRole
192+
export const getAllByRole: typeof AllByRole
193+
export const queryByRole: typeof QueryByRole
194+
export const queryAllByRole: typeof AllByRole
195+
export const findByRole: typeof FindByRole
196+
export const findAllByRole: typeof FindAllByRole
169197
export const getByTestId: GetByBoundAttribute
170198
export const getAllByTestId: AllByBoundAttribute
171199
export const queryByTestId: QueryByBoundAttribute

0 commit comments

Comments
 (0)