【问题标题】:How to import a js Module as any. (Without any declaration file (d.ts))如何导入任何 js 模块。 (没有任何声明文件(d.ts))
【发布时间】:2021-09-28 04:40:18
【问题描述】:

所以我想在我的 ts 应用程序中导入一个 js 模块。

有没有办法做到这一点制作d.ts文件或者如果 不知道如何在d.ts 文件中将其声明为any

我目前只是用 //@ts-ignore 忽略此错误。

谢谢!

【问题讨论】:

标签: javascript typescript import typescript-typings typescript2.0


【解决方案1】:

这里有两种情况:

  • 您正在使用 ESM 模块,并且只有 import(...) 可用
const module = (await import('module')) as any;
  • 您没有使用 ESM 模块,因此您可以访问 require(...)
const module = require('module') as any;

【讨论】:

    猜你喜欢
    • 2018-03-28
    • 1970-01-01
    • 1970-01-01
    • 2020-03-23
    • 1970-01-01
    • 1970-01-01
    • 2018-10-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多