TypeScript error reassigning a variable using within #979
Labels
bug
Something isn't working
TypeScript
Related to TypeScript. Note: only certain maintainers handle TypeScript labeled issues.
Uh oh!
There was an error while loading. Please reload this page.
@testing-library/react
version: 12.1.2Relevant code or config:
What you did:
I am learning TypeScript and have converted a React project including all tests.
What happened:
When attempting to reassign a variable using
within
I am getting a TS error.Reproduction:
https://www.typescriptlang.org/play?#code/JYWwDg9gTgLgBAbzgZwMZQKYYHYBo4DuwMAFsNnAL5wBmUEIcARAAIwbIzkDmAtADbAARlACGUAJ4B6ACYMmAbgBQoSLGZsJYDlIBWHGIpXho8Vu048BwsZL0HeckEaWoI2TnGyiAbsG6iXO5wALwo6FjYAHTcGDAAQhIAShD8GAAUTN5+AUHYTACUymnwIhiiMugAriBCyKGExGTY6dn+gcDuRUoYAB7aqDDpZRXVtcgxcYkpaZmC2ADWTPhI3iAYAFxwUiQMGFLAVAUFUTAQ8RgAktgAKiQYACIQqDU4Q90jlVA1dQ1EpORWr52nkikA
Problem description:
This is very strange as it looks like the two calls to
within
are returning a different type. I asked for help in the Testing Library Discord channel and was pointed at the Discord TypeScript channel where I received this response:https://discord.com/channels/508357248330760243/746024503817011220/898609497206063124
Suggested solution:
One solution is to use
any
:Another is to use a different variable altogether.
Being new to TypeScript I have no idea what is going on here or how to fix it properly.
The text was updated successfully, but these errors were encountered: