【发布时间】:2021-11-26 21:00:24
【问题描述】:
我正在开发一个使用 react-spring 的组件库的项目。我无法控制组件库,因此我无法控制它使用 react-spring v8 的事实
我在 PR 上找到了 comment,它告诉我如何在测试环境中运行时修复动画。它需要我导入 Globals 对象。当我尝试通过import { Globals } 这样做时,我收到错误消息Module '"react-spring"' has no exported member 'Globals'.ts(2305),因为我的项目正在使用 Typescript(其中的说明适用于 JS)
当我查看我的 node_modules 目录中 react-spring 的代码时,我可以看到 Globals 对象肯定在主代码和模块代码中都被导出了。
web.js(主要):
export { apply, config, update, extendedAnimated as animated, extendedAnimated as a, interpolate$1 as interpolate, Globals, useSpring, useTrail, useTransition, useChain, useSprings };
web.cjs.js(模块):
exports.Globals = Globals;
但是,当我查看 types provide by react-spring 时,Globals 没有任何内容,我担心这会导致我无法导入 Globals,以便我可以在测试期间按照指示提供模拟 requestAnimationFrame。
我对 Typescript 很陌生,所以我可能误解了某些东西,我已经尝试 Google 解决方案,但我几乎只能找出如何处理一个没有类型的库关于如何修复库提供的类型中的“漏洞”的所有内容。
这是一个显示相同错误的 CodeSandbox(必须正在编辑沙箱。不在预览模式下显示。
【问题讨论】: