Skip to content

Commit 1f143e5

Browse files
Dennis273eps1lon
andauthored
fix(within): Add extra type paramater to allow reassigning in TypeScript (#1077)
Co-authored-by: eps1lon <[email protected]>
1 parent b4ebc80 commit 1f143e5

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

types/__tests__/type-tests.ts

+6
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,12 @@ export async function testWithin() {
254254

255255
await container.findByRole('button', {name: /click me/i})
256256
container.getByRole<HTMLButtonElement>('button', {name: /click me/i})
257+
258+
let withinQueries = within(document.body)
259+
withinQueries = within(document.body)
260+
withinQueries.getByRole<HTMLButtonElement>('button', {name: /click me/i})
261+
withinQueries = within(document.body)
262+
withinQueries.getByRole<HTMLButtonElement>('button', {name: /click me/i})
257263
}
258264

259265
/*

types/get-queries-for-element.d.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,8 @@ export interface Queries {
175175
[T: string]: Query
176176
}
177177

178-
export function getQueriesForElement<T extends Queries = typeof queries>(
179-
element: HTMLElement,
180-
queriesToBind?: T,
181-
): BoundFunctions<T>
178+
export function getQueriesForElement<
179+
QueriesToBind extends Queries = typeof queries,
180+
// Extra type parameter required for reassignment.
181+
T extends QueriesToBind = QueriesToBind,
182+
>(element: HTMLElement, queriesToBind?: T): BoundFunctions<T>

0 commit comments

Comments
 (0)