-
Notifications
You must be signed in to change notification settings - Fork 63
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
Broken type definition in focus-trap-react 11 #1396
Comments
`export declare class` means that there are named exports, but there are no named exports in src/focus-trap-react.js. Therefore, `export = FocusTrap;` was the correct type definition. Fixes focus-trap#1396
@Mathias-S 🤦♂️ Thank you for being quick to file this and help me out with a PR to correct it. I believe my actual intent (months ago when I prepared the changes ahead of React 19's official release) was to move away from the default export since Tabbable and Focus-trap exclusively use named exports and I generally feel that's a better way to go for bundlers. So I figured I'd use the breaking change opportunity of v11 to move to that, but completely missed adjusting the code after adjusting the types, and also mentioning it in the changelog which I prepared just before publishing. I guess I will kick that can down the road again since I kind of missed the major version opportunity at this point. Introducing what would technically be another breaking change in a patch to fix the code to match the types doesn't feel great, and neither does doing back-to-back major releases. 🫤 |
I agree that named exports are better than default exports. Maybe a temporary solution would be to provide both? And then also mark the default export as deprecated using JSDoc |
@Mathias-S I like that idea! At least it's progress toward the goal as I (ever so) slowly refactor this library. I'd love to have it be 100% TypeScript some day instead of have "tangential" types like it does today. |
Fixes #1396 My original intent was to remove the default export (a breaking change) as part of the major 11.0.0 release but I totally flopped on that by not also actually providing the named export in the code. Now that the major release ship has sailed, this change fixes the types by reinstating the default export in the typings but marking it deprecated, while also providing the new named export alternative as the way forward.
@Mathias-S I have opened #1406 to do as you suggested (and closed #1397): Provide both exports and mark the default export as deprecated. I tested this in your local |
@all-contributors add @Mathias-S for bug, review |
I've put up a pull request to add @Mathias-S! 🎉 |
Description
I am using ESM-style imports and exports in my project.
The change from
export = FocusTrap
toexport declare class FocusTrap
in index.d.ts means that it is now only possible to use named imports, i.e.import { FocusTrap } from "react-focus-trap"
(according to the types).However, this is incompatible with
module.exports = FocusTrap;
in src/focus-trap-react.js, which only lets you do default imports, i.e.import FocusTrap from "react-focus-trap"
.So the type change needs to be reverted so only default imports works, or a named export should be provided instead:
But that would obviously also be a breaking change. It is technically possible to hack it and provide both a named and default export with CJS:
Versions
Sandbox
Minimal reproduction in CodeSandbox should display the type error in the editor: https://codesandbox.io/p/sandbox/5fz5r4
Local repro
The text was updated successfully, but these errors were encountered: