我有一个用 JavaScript 编写的应用程序,我想使用 TypeScript 来实现新功能。例如,我有一个用 JavaScript 定义的基类。
// base.js
module.exports = function BaseClass () {
// ... ...
};
在我的 TypeScript 中,我需要像这样创建一个类。
// sub.ts
import Base from "./base.js";
class Sub extends Base {
// ... ...
}
但是我发现sub.ts
说有错误
Type "Base" is not a constructor function type.
我想知道为什么会出现这种情况?这是因为我的 base.js
没有 .d.ts
文件吗?如果是这样,我如何为 base.js
创建明确的文件以及我需要将该文件放在哪里?
最佳答案
Is this because there's no .d.ts file for my base.js?
是的。
If so, how can I create the definitely file for base.js
简单地base.d.ts
:
declare class Base {
}
and where I need to put this file?
在 base.js
旁边。
关于typescript - 为我自己的 JavaScript 文件编写 .d.ts 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47861868/