reactjs - 在打字稿模块中导入 ReactNode 失败
问题描述
我有一个 create-react-app ,其中包含以下types
目录src
:
testapp-components.d.ts
import { ReactNode } from "react";
interface Option {
label: ReactNode;
value: string;
[key: string]: ReactNode;
}
declare module "@testApp/components";
但是,当我在我的组件中使用它时......
// @testApp/components is an internal library I've installed. OptionSelector is a custom react component.
import { OptionSelector } from @testApp/components;
... other React code ...
const [options, setOptions] = useState<Option[]>([]);
它给了我以下错误:
TS7016: Could not find a declaration file for module '@testApp/components
在下面import { OptionSelector } ...
TS2304: Cannot find name Option
在 useState 下
如果我删除import { ReactNode } ...
并更改对这两个错误的ReactNode
引用any
都消失了......
将文件名更改为.d.tsx
不能解决问题。
我也试过这个:
declare module "@testApp/components" {
export interface Option {
label: any;
value: string;
[key: string]: any;
}
};
这为 useState 产生了相同的错误,但给了我一个新的错误import { OptionSelector } ...
:
TS2305: Module @testApp/components has no exported member OptionSelector
解决方案
推荐阅读
- python - 如何将 2D 和 1D 类(分别为单热编码和常规整数)的混合输入到 Keras 序列模型中?
- java - android - java.lang.ArrayIndexOutOfBoundsException:长度=4;index = 4长度数组 - Thinbug
- marklogic - 使用管理 API 在 MarkLogic 9.2 上设置元数据字段
- django - 在 Django 默认环境之外的数据库中替换/更改文件路径
- portal - 我可以从 TFS/VSTS 发布 Dynamics 365 门户页面吗
- php - 如何在 Laravel 中将元字段添加到 Eloquent 模型对象的集合中
- hibernate - HQL 奇怪的行为
- opengl - 如何将 opengl 用于 nana c++ 库?
- c++ - 为什么找不到我的着色器属性?
- optimization - 确切的 Broadcom B43 驱动程序