Skip to content

Commit

Permalink
fix(within): Add extra type paramater to allow reassigning in TypeScr…
Browse files Browse the repository at this point in the history
…ipt (#1077)

Co-authored-by: eps1lon <silbermann.sebastian@gmail.com>
  • Loading branch information
Dennis273 and eps1lon authored Jan 15, 2022
1 parent b4ebc80 commit 1f143e5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
6 changes: 6 additions & 0 deletions types/__tests__/type-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,12 @@ export async function testWithin() {

await container.findByRole('button', {name: /click me/i})
container.getByRole<HTMLButtonElement>('button', {name: /click me/i})

let withinQueries = within(document.body)
withinQueries = within(document.body)
withinQueries.getByRole<HTMLButtonElement>('button', {name: /click me/i})
withinQueries = within(document.body)
withinQueries.getByRole<HTMLButtonElement>('button', {name: /click me/i})
}

/*
Expand Down
9 changes: 5 additions & 4 deletions types/get-queries-for-element.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ export interface Queries {
[T: string]: Query
}

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

0 comments on commit 1f143e5

Please sign in to comment.