-
Notifications
You must be signed in to change notification settings - Fork 274
fix: fixing TypeScript accessibility issue for custom render function #1428
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@FelipeESchmidt the error you are getting seems weird, afaik TS should be able to use the type's shape without using it's name. Are you experiencing it with an app or are you creating your own librarary/package? |
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## main #1428 +/- ##
=======================================
Coverage 96.89% 96.89%
=======================================
Files 65 65
Lines 3709 3709
Branches 539 539
=======================================
Hits 3594 3594
Misses 115 115
☔ View full report in Codecov by Sentry. |
@@ -136,7 +136,7 @@ function updateWithAct( | |||
}; | |||
} | |||
|
|||
interface DebugFunction { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You probably need to add it to package public exports in pure.ts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added the type DebugFunction to the pure.ts
export types in my last commit. That's what you meant?
I'm currently using it with an app and the tests gotta use some wrappers, then I've created a custom render to add them around my component that is being tested. |
Hello @FelipeESchmidt, thanks or submitting this pr! I can't reproduce the issue, I suspect it's due to a difference in typescript config, could you please copy your |
Sure, follow below:
Was you able to create a custom render without the problem? If yes, could you share it? |
You see this error because you have I still believe that this type should be exported though since it's part of the public API and there may be valid use cases for wanting to generate declaration files |
@pierrezimmermannbam Thank you very much for the explanation! I really don't know if the project's configuration needs to be the way it currently is, since it's the application where I work and I wasn't there during the project's creation. But again, thank you so much! |
This PR has been released in v12.1.3 🚢 |
Summary
This Pull Request addresses a problem encountered when trying to use a custom render function in TypeScript. The issue throws an error:
"Exported variable 'customRender' has or is using name 'DebugFunction' from external module '/node_modules/@testing-library/react-native/build/render' but cannot be named."
To resolve this problem, we're exporting the DebugFunction interface from the module it's declared in. This change will allow the TypeScript compiler to recognize the DebugFunction type when it's used in external modules, thus eliminating the naming error that is currently being thrown.
Test plan
The error:
With this change the error goes away:
The error can be solved in the custom render by using
RenderResult
as the return type, but it'd be nice to work directly. 😀