【问题标题】:'React' is declared but its value is never read'React' 被声明但它的值从未被读取
【发布时间】:2023-03-15 09:33:01
【问题描述】:

我有以下代码:

// tslint:disable
import * as React from 'react';
import { Input, InputProps } from '../atoms/Input/Input';
import { FormControl } from '../hoc/FormControl/FormControl';

export const FormInput = FormControl<InputProps>(Input);

Typescript 不会编译它但会报错:

'React' 已声明,但它的值从未被读取。

如果我删除我得到的行:

导出的变量“FormInput”已经或正在使用来自外部模块“/node_modules/@types/react/index”的名称“React.ComponentClass”,但无法命名。 [ts] 导出的变量“FormInput”已经或正在使用来自外部模块“/node_modules/@types/react/index”的名称“React.StatelessComponent”,但无法命名。

我在 tsconfig 中将 declaration 设置为 true,这是正确的,因为这是一个包。

【问题讨论】:

    标签: typescript


    【解决方案1】:

    尝试升级到 TypeScript 2.9 或更高版本。 TypeScript 2.9 添加了对import types 的支持,这应该可以删除React 的导入并仍然生成声明文件。

    【讨论】:

      【解决方案2】:

      更新 tsconfig.json

      {
        "compilerOptions": {
           "jsx": "react"
        }
      }
      

      【讨论】:

        猜你喜欢
        • 2019-06-23
        • 1970-01-01
        • 2021-12-23
        • 1970-01-01
        • 2022-08-10
        • 2018-09-28
        • 1970-01-01
        • 2021-02-25
        • 2019-08-24
        相关资源
        最近更新 更多