问题描述
我想为 p5.play.js 生成一个 d.ts 文件,因为没有任何文件,而且因为 p5.play.js 是一个大库,所以输入它会很痛苦,而且我对 d 很陌生。 ts 文件显示我只知道如何声明函数,而 p5.play.js 也有属性。但是当我使用 try 创建它时,它会创建一个带有 export {};
以下是我尝试过的方法:
{
// 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"
}
}
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 存储库中,希望对您有所帮助!!