typescript - TSC 未找到 NPM 库的自定义 .d.ts 文件
问题描述
import audioConcat from 'audioconcat';
Could not find a declaration file for module 'audioconcat'. '/home/owner/projectDir/node_modules/audioconcat/index.js' implicitly has an 'any' type.
Try `npm install @types/audioconcat` if it exists or add a new declaration (.d.ts) file containing `declare module 'audioconcat';`ts(7016)
这个 NPM 库没有自己的类型,或者绝对类型上的社区包:https ://www.npmjs.com/package/audioconcat
// src/types/audioconcat/index.d.ts
declare module "audioconcat" {
export default class AudioConcat {
constructor(audios: Array<string>);
VERSION: string;
ffmpeg: Function;
concat(images: string[], options: any): this;
on(event: 'start', callback: (command: any) => void): this;
on(event: 'error', callback: (err: any, stdout: any, stderr: any) => void): this;
on(event: 'end', callback: (output: any) => void): this;
}
}
还有我的 tsconfig.json:
{
"compilerOptions": {
"target" : "ES5",
"module": "commonjs",
"noImplicitAny": true,
"removeComments": true,
"sourceMap": true
, "outDir": "compiled/"
, "esModuleInterop": true
, "strict": true
, "typeRoots": ["./src/types", "node_modules/@types"]
},
"include": ["src/**/*"]
, "exclude": ["node_modules", "compiled", "__tests__", "types"]
}
// On line 1: Cannot find type definition file for 'audioconcat'.ts
我缺少什么细节让 Typescript 在重新运行后不检测这个声明文件tsc
?
解决方案
推荐阅读
- r - ggplot shape = Unicode(例如像“\u2198”或LaTeX \searrow这样的箭头)?
- ruby-on-rails - How to render an image from a remote url
- java - 自定义注释以包装注释
- actions-on-google - 通过快速自托管迁移到 v2 API
- python-3.x - Python sqlite3,在 .format 的帮助下从列表中创建表列
- php - 找到数组元素后取出每个元素
- azure-devops - Azure DevOps 条件编译
- matlab - 在 MATLAB 中查找单个点的最近邻
- javascript - 如何将 Target 属性添加到新的 MouseEvent?
- javascript - 模板按钮不适用于 Javascript