You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It fixed the case with bound find* queries, now they accept waitForElementOptions argument, but it breaks proper typechecking for get* and other bound queries, that accept fewer arguments. For some reason typescript uses this signature for them too, which results in ability to call them with more arguments than they accept.
Example:
const{ getByText }=render(<App/>);
constbutton=getByText(// TS should throw error here, but doesn't/inc/i,{},{timeout: 100});
I probably don't fully understand how assignability rules work for function signatures in conditional types in Typescript(I think it should be from top to bottom, from more to less specific signatures). Would be great if someone could find a solution to this.
The text was updated successfully, but these errors were encountered:
le0nik
changed the title
bound function for find* methods throws error in typescript
Bound functions for find* queries throw error in typescript when waitForElementOptions argument is supplied.
Jun 20, 2019
dom-testing-library
version: 5.2.1react-testing-library
version: 8.0.1react
version: 16.8.6node
version: 10.16.0npm
(oryarn
) version: npm(6.9.0), yarn(1.16.0)Relevant code or config:
What you did:
Used bound
findByText
function returned byrender
from@testing-library/react
withwaitForElementOptions
argument.What happened:
Typescript threw an error
Expected 1-2 arguments, but got 3
Reproduction:
https://codesandbox.io/s/uok74
Take a look at
App.test.tsx
.Problem description:
waitForElementOptions
argument is not considered for bound functions type here:dom-testing-library/typings/get-queries-for-element.d.ts
Lines 4 to 13 in 349f497
Suggested solution:
Another signature should be added that supports
waitForElementOptions
argument to the type linked above.I tried to do that, but my attempt failed. Here's what I've tried:
Note these 2 lines that I've added:
It fixed the case with bound
find*
queries, now they acceptwaitForElementOptions
argument, but it breaks proper typechecking forget*
and other bound queries, that accept fewer arguments. For some reason typescript uses this signature for them too, which results in ability to call them with more arguments than they accept.Example:
I probably don't fully understand how assignability rules work for function signatures in conditional types in Typescript(I think it should be from top to bottom, from more to less specific signatures). Would be great if someone could find a solution to this.
The text was updated successfully, but these errors were encountered: