首页 > 解决方案 > 如何设置节点模块导出类型信息

问题描述

我正在编写一个节点模块,它是我的反应和反应本机应用程序的 api 层。我已经达到了打字稿导出除type对象之外的所有内容的地步。据我了解,我可以为我的项目创建自定义类型,但这似乎没有必要。这是我编译的index.d.ts文件的样子

import InventoryService from "./src/services/InventoryService";
import PlentiItemService from "./src/services/PlentiItemService";
...
declare type PlentiType = "Fruit" | "Decorative" | "Herb" | "Poultry" | "Vegetable" | "Unknown";
declare type QuantityName = "None" | "A Little" | "Some" | "A Lot" | "Many";
export { AccountLoginForm, AccountSignupForm, AccountUpdateForm, ..., PlentiType, QuantityName}

请注意,这些类型已导出,但在安装应用程序中似乎不可用。这是为什么?

标签: node.jsreactjstypescriptreact-nativenpm

解决方案


请注意,类型已导出,但在安装应用程序中似乎不可用。这是为什么

假设你"main" : "lib"的 package.json 中有(js 文件的路径),你的 package.json 中也需要有 `"types": "lib" (.d.ts 文件的路径)。

如果您没有.d.ts编译出文件,请确保您tsconfig.jsondeclaration: true

更多的


推荐阅读