【问题标题】:Problem generating d.ts files from p5.play.js when using tsc使用 tsc 时从 p5.play.js 生成 d.ts 文件的问题
【发布时间】:2021-05-28 13:12:13
【问题描述】:

我想为 p5.play.js 生成一个 d.ts 文件,因为没有任何文件,而且由于 p5.play.js 是一个大库,所以输入它会很痛苦,而且我对 d 很陌生。 ts 文件显示我只知道如何声明函数,p5.play.js 也有属性。但是当我尝试创建它时,它会创建一个带有export {};的空d.ts文件

这是我尝试过的事情:

  1. 我尝试使用 tsconfig.json 和 tsc 来生成文件,但结果是 export {};,这是我用于 tsc 的配置:
{
  // Change this to match your project
  "include": ["src/"],
  "compilerOptions": {
    // Tells TypeScript to read JS files, as
    // normally they are ignored as source files
    "allowJs": true,
    // Generate d.ts files
    "declaration": true,
    // This compiler run should
    // only output d.ts files
    "emitDeclarationOnly": true,
    // Types should go into this directory.
    // Removing this would place the .d.ts files
    // next to the .js files
    "outDir": "dist"
  }
}

并且是我拥有 p5.play.js 文件的 src 文件夹

  1. 我尝试将 d.ts make 与 main.js 一起使用,然后再次创建了一个 d.ts 文件:export {};,这是我用于 dts make 的 main.js:
require('dts-generator').default({
        name: 'p5.play',
        project: 'src/',
        out: 'p5.play.d.ts'
});

再次在 src 中,我有 p5.play.js。

如果有帮助,这里是 dts gen/make https://www.npmjs.com/package/dts-generator 的 npm 这是 p5.play.js 库:https://github.com/molleindustria/p5.play/blob/master/lib/p5.play.js

【问题讨论】:

    标签: javascript typescript tsc .d.ts


    【解决方案1】:

    我也遇到了和你一样的问题,所以我没有找到预定义的 p5.play.d.ts,而是为 p5.play 创建了自己的文件。该文件在我的 GitHub 存储库中,希望对您有所帮助!

    文件链接 -> https://github.com/VisualCode44/Definition-File

    【讨论】:

    • 这工作非常感谢你我已经等了 2 个月的答案了
    猜你喜欢
    • 2019-01-07
    • 2018-03-05
    • 1970-01-01
    • 2017-12-11
    • 1970-01-01
    • 1970-01-01
    • 2019-08-14
    • 2021-09-06
    • 2011-12-29
    相关资源
    最近更新 更多