带有typescript的示例React本机项目有许多类型错误

带有typescript的示例React本机项目有许多类型错误,typescript,react-native,Typescript,React Native,我按照文档生成了一个示例项目 npx react-native init MyApp --template react-native-template-typescript 然后,我开始了这个项目并开始运行 tsc 我得到了183个错误,似乎所有的错误都来自node_模块 3237 use: React.SVGProps<SVGUseElement>; ~~~ node_modules/@types/react/in

我按照文档生成了一个示例项目

npx react-native init MyApp --template react-native-template-typescript
然后,我开始了这个项目并开始运行

tsc
我得到了183个错误,似乎所有的错误都来自node_模块

3237             use: React.SVGProps<SVGUseElement>;
                 ~~~

  node_modules/@types/react/index.d.ts:3234:13
    3234             use: React.SVGProps<SVGUseElement>;
                     ~~~
    'use' was also declared here.

node_modules/@types/react-test-renderer/node_modules/@types/react/index.d.ts:3238:13 - error TS2717: Subsequent property declarations must have the same type.  Property 'view' must be of type 'SVGProps<SVGViewElement>', but here has type 'SVGProps<SVGViewElement>'.

3238             view: React.SVGProps<SVGViewElement>;
                 ~~~~

  node_modules/@types/react/index.d.ts:3235:13
    3235             view: React.SVGProps<SVGViewElement>;
                     ~~~~
    'view' was also declared here.

node_modules/@types/react/index.d.ts:3047:14 - error TS2300: Duplicate identifier 'LibraryManagedAttributes'.

3047         type LibraryManagedAttributes<C, P> = C extends React.MemoExoticComponent<infer T> | React.LazyExoticComponent<infer T>
                  ~~~~~~~~~~~~~~~~~~~~~~~~

  node_modules/@types/react-test-renderer/node_modules/@types/react/index.d.ts:3048:14
    3048         type LibraryManagedAttributes<C, P> = C extends React.MemoExoticComponent<infer T> | React.LazyExoticComponent<infer T>
                      ~~~~~~~~~~~~~~~~~~~~~~~~
    'LibraryManagedAttributes' was also declared here.


Found 183 errors.
到tsconfig文件,但编译器会忽略节点_模块外部的所有.d.ts文件

有谁能想出更好的解决办法吗?
非常感谢 问题是同一模块的不同副本中有两个相互冲突的类型定义<代码>@types/react尤其如此

正如您在错误日志中看到的,它指的是
@types/react
@types/react测试呈现器/../@types/react
。这是因为
@types/react测试呈现程序
具有不兼容版本的
@types/react
依赖项,并且npm/Thread必须将这两个版本安装到
节点_模块中
。这个问题(大多数情况下)可以通过功能解决


尽管
--skipLibCheck
是缓解此类问题的常见做法。此外,启用它可以大大缩短大型项目的编译时间。

您是否尝试升级@types/node?请尝试使用
--skipLibCheck
运行,这将防止对
节点模块
目录进行表单检查。@Juanjo它已经是最新的
"skipLibCheck": true