reactjs - Typescript 使用最新的样式组件引发错误
问题描述
我有一个使用 React、TypeScript 和样式组件的项目。我已经在这个项目上工作了一段时间,然后决定将 styled-components 升级到最新版本,即5.1.1
(2.4.1
以前是)。因此,该项目编译并正常运行,但是当我尝试实际构建它时,它会引发以下错误:
node_modules/@types/styled-components/ts3.7/index.d.ts:151:69 - error TS2694:
Namespace '"C:/path/node_modules/hoist-non-react-statics/index"' has no exported member 'NonReactStatics'.
151 string & StyledComponentBase<C, T, O, A> &
hoistNonReactStatics.NonReactStatics<C extends React.ComponentType<any> ? C : never>;
node_modules/@types/styled-components/ts3.7/index.d.ts:253:65 - error TS2344:
Type 'C' does not satisfy the constraint 'ComponentType<any>'.
Type 'ElementType<any>' is not assignable to type 'ComponentType<any>'.
Type '"symbol"' is not assignable to type 'ComponentType<any>'.
Type 'C' is not assignable to type 'FunctionComponent<any>'.
Type 'ElementType<any>' is not assignable to type 'FunctionComponent<any>'.
Type '"symbol"' is not assignable to type 'FunctionComponent<any>'.
253 ? React.ComponentPropsWithRef<StyledComponentInnerComponent<C>>
我尝试了不同版本的 TypeScript、旧版本的样式组件、新版本的 Node.js,但所有这些都给了我各种错误。tsconfig.json
一些设置只抛出两个错误,其他抛出 15 个错误。如果它有助于理解问题,我可以附上我的。我的 TypeScript 版本目前是3.7.
据我了解,styled-components 用于满足其需求的包内部存在一些不兼容性。但我不知道如何解决它们。
解决方案
推荐阅读
- python - 如何从 django 上的 postgres 表和字段名称中删除双引号?
- xcode - 如何在构建机器上使用 Xcode 11 托管签名进行构建以进行分发
- c# - 如何将 SqlCommand 查询转换为使用使用连接字符串构建的参数,包括使用三元运算符的变量
- sql - 使用代码行运行 SAS 程序(在 SAS 项目内部)
- swift - 如何根据第一个 VC 按钮上的标题来更改下一个视图控制器?
- apache-kafka - 当您在 Kafka 消费者/客户端上获得“太多打开的文件”时,这意味着什么?
- docker - 如何使用 Docker compose 定义子网和 IP 地址并将其分配给容器
- amazon-web-services - EC2 上的 Jenkins 管道在 ECR 中推送图像
- javascript - 如果选择还包含相同嵌套元素的整个树,我如何才能只抓取一次 DOM 元素的内容?
- ssl - HAProxy 安全重新协商