【发布时间】:2020-12-27 13:31:05
【问题描述】:
我在 react native 项目中有这个文件:
import styled, { withTheme } from 'styled-components';
import { BaseText } from '../BaseText';
export interface BodyProps {
textAlign?: string;
fontSize?: string;
}
export const Body = withTheme(styled(BaseText)<BodyProps>`
text-align: ${props => (props.textAlign ? props.textAlign : 'center')};
font-size: ${props => (props.fontSize ? props.fontSize : '16px')};
`);
我将 react native 从 0.61.5 升级到 0.63.2 并开始在使用 withTheme 的任何地方出现此 lint 错误:
TS2742:“身体”的推断类型不能在没有名称的情况下命名 参考'react-native/node_modules/@types/react'。这很可能 不便携。需要类型注释。
我尝试了几件事,但错误仍然存在:
- 在this post 之后,我添加了
import React from "react"; - 尝试通过在
Body声明上方添加/* tslint:disable */来禁用 tslint - 尝试通过在
Body声明上方添加// tslint:disable-next-line来禁用 tslint - 使用依赖版本。目前我有
"@types/react": "^16.9.49"。
【问题讨论】:
-
你有重复的类型,这就是它的意思。查看路径,它是一个嵌套在
node_modules/react-native/中的node_modules目录你有冲突的依赖项 -
@AluanHaddad 谢谢,但
@types里面没有node_modules/react-native/目录 -
这很奇怪。删除
node_modules和package-lock.json或任何用于您的包管理器的锁定文件并重新安装所有依赖项
标签: typescript react-native styled-components tslint prettier