首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从模块导入“私有”TypeScript声明,而不是通过package.json公开它

从模块导入“私有”TypeScript声明,而不是通过package.json公开它
EN

Stack Overflow用户
提问于 2021-03-05 22:47:00
回答 1查看 220关注 0票数 1

当导入npm模块的组件时,它的package.json没有公开,如下所示

代码语言:javascript
复制
import {Toolbar} from "@atlaskit/editor-core/dist/esm/ui/Toolbar";

tsc / webpack找不到合适的申报文件。

来源和类型见:

代码语言:javascript
复制
node_modules/@atlaskit/editor-core/dist/esm/ui/Toolbar/Toolbar.js
node_modules/@atlaskit/editor-core/dist/types/ui/Toolbar/Toolbar.d.ts

如何正确链接声明并防止

TS7016:找不到模块“@atlaskit/editor-core/dist/esm/ui/Toolbar”的声明文件。'.../node_modules/@atlaskit/editor-core/dist/esm/ui/Toolbar/index.js‘隐式地具有“任意”类型。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-03-09 05:49:15

因为包有声明文件,所以很容易将深度导入连接起来使用其类型。

向项目中添加一个typings.d.ts声明文件以添加环境模块声明:

代码语言:javascript
复制
// assert that an import module of this path HAS types
declare module '@atlaskit/editor-core/dist/esm/ui/Toolbar' {
  // assert that this module contains all exports of the existing declaration file
  export * from '@atlaskit/editor-core/dist/types/ui/Toolbar';
}

相关Stackblitz

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66500545

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档