使用 tsc 时从 p5.play.js 生成 d.ts 文件的问题

问题描述

我想为 p5.play.js 生成一个 d.ts 文件,因为没有任何文件,而且因为 p5.play.js 是一个大库,所以输入它会很痛苦,而且我对 d 很陌生。 ts 文件显示我只知道如何声明函数,而 p5.play.js 也有属性。但是当我使用 try 创建它时,它会创建一个带有 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 这是 p5.play.js 库:https://github.com/molleindustria/p5.play/blob/master/lib/p5.play.js

解决方法

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

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