【问题标题】:Typescript declaration file giving me error in VSCode打字稿声明文件在 VSCode 中给我错误
【发布时间】:2016-10-13 01:28:20
【问题描述】:

我试图在我的节点模块中添加一个打字稿声明文件,但在 VS Code 的另一个项目中使用它时遇到错误:

导出的外部包类型文件 .../ttk.d.ts 不是模块

有问题的 ttk.d.ts 文件是 here

奇怪的是,在 VS Code 中,我使用声明文件自动完成。有谁知道我做错了什么?

编辑:这是导入模块的测试文件:

const ttk = require('ttk');

const t = ttk.factory();
const r = t`Hello, ${'@name'}!`;
const s = r({ name: 'World' });

console.log(s);

【问题讨论】:

标签: typescript visual-studio-code typescript-typings


【解决方案1】:

基本上该文件被声明为全局代码(因为它没有顶级导入或导出),但 TypeScript 期望该文件是一个模块。

如果您查看被引用的.d.ts,则需要将declare module "ttk" 的内容移到顶层,以便将该文件视为一个模块。

我在这里发送了一个 PR 来解决这个问题:https://github.com/maexsoftware/ttk/pull/7

希望有帮助!

【讨论】:

猜你喜欢
  • 2021-11-10
  • 1970-01-01
  • 1970-01-01
  • 2017-09-12
  • 2017-02-16
  • 2018-03-11
  • 1970-01-01
  • 1970-01-01
  • 2013-08-20
相关资源
最近更新 更多