jianghuyihong 2019-04-12 10:45 采纳率: 0%
浏览 1456

typescript 全局函数怎么使用?

在ts里面写了一个全局函数
declare class Animal {
constructor(name: string);
sayHi(): string;
}

let cat = new Animal('Tom');

但编译成js后成:
var cat = new Animal('Tom');
运行js时报错:ReferenceError: Animal is not defined
为什么,应该怎么使用这个全局函数?

  • 写回答

1条回答 默认 最新

  • 前端呆头鹅 2023-03-28 17:22
    关注

    declare需要写在.d.ts文件中,文件后缀名是否正确?

    评论

报告相同问题?