Typescript 如何为导出函数的模块创建声明文件?
我需要为导出函数的JavaScript模块创建声明文件。JavaScript模块如下所示:Typescript 如何为导出函数的模块创建声明文件?,typescript,Typescript,我需要为导出函数的JavaScript模块创建声明文件。JavaScript模块如下所示: module.exports = hello function hello() { console.log('Hello') } 我尝试用不同的方法创建声明文件: export function hello(): void 任何类型的导入都不起作用: import hello from './filename' 如何为这些模块创建声明文件?您要处理的是commonJS中的默认导出: modules
module.exports = hello
function hello() { console.log('Hello') }
我尝试用不同的方法创建声明文件:
export function hello(): void
任何类型的导入都不起作用:
import hello from './filename'
如何为这些模块创建声明文件?您要处理的是commonJS中的默认导出:
modules.exports=hello
在声明.d.ts
文件中,您不应该像看上去那样重新实现函数行为。您只需要声明它的类型。我相信这可以做到:
声明函数hello():void
导出=你好
您也可以始终使用.D.TS选项卡中的TS Playway来使用TS为您生成声明的功能:
查看更多信息抱歉。实施是问题中的一个错误。关键是:
导出默认值
不起作用。我的错误。就像我在上面的答案中编辑的那样,尝试导出=你好。
declare function hello(): void
export = hello
import hello from './filename'
import { hello } from './filename'