reactjs - 如何摆脱我的 "@types/react/index"只能在 React/TypeScript 中使用 'esModuleInterp' 标志 Lint 默认导入

标签 reactjs typescript eslint

就像上面说的一样简单:React 16.9.22 和 TypeScript 3.8.2。它不会影响任何事情,只是挤满了我的警告窗口表单实际上有用的东西。

在我的 tsconfig 我有:

{
  "compilerOptions": {    
    "esModuleInterop": true
  }
}

但是每个文件都有一行 import React from 'react';
我收到掉毛错误:

.../node_modules/@types/react/index"' can only be default-imported using the 'esModuleInterop' flag



可能相关的部门:
  "devDependencies": {
    "@typescript-eslint/eslint-plugin": "^2.22.0",
    "@typescript-eslint/parser": "^2.22.0",
    "cross-env": "^5.2.0",
    "eslint": "^6.6.0",
    "eslint-config-react-app": "^4.0.1",
    "eslint-plugin-flowtype": "^2.0.0",
    "eslint-plugin-import": "^2.14.0",
    "eslint-plugin-jsx-a11y": "^6.2.1",
    "eslint-plugin-react": "^7.18.3",
    "typescript": "^3.8.2"
  },

最佳答案

如上所述,我现在使用它,有没有人知道如何将它作为单线?

import * as React from 'react'
import {
    useState, useEffect
}  from 'react';
这不起作用:
import * as React, {
    // useEffect,
    useState, useEffect
}  from 'react';

关于reactjs - 如何摆脱我的 "@types/react/index"只能在 React/TypeScript 中使用 'esModuleInterp' 标志 Lint 默认导入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60551025/

相关文章:

javascript - 上下文 API,如何不使用类?

angular - 在我的案例中,如何捆绑 Angular 2 应用程序进行生产?

typescript - 基于泛型的类字段类型

eslint - 将默认错误级别设置为 WARN

javascript - 在 React 中,孙子可以访问祖 parent 的属性而无需 parent 将其传递下去吗?

javascript - 我认为我的 css 类已导入,但我已正确导入它

angular - 检测 Angular 形式(非响应式)中的数据是否已更改

javascript - 防止旧式函数声明

javascript - ESLint 偏好反射(reflect)错误

javascript - ReactJS-目录选择对话框不起作用