我意识到这真的很简单,但是typescript似乎在过去的几年里发生了很大的变化,我就是不能用我在堆栈溢出上找到的以前的答案来完成这个任务。
let myfunction = something that returns a function
export myfunction;我得到一个错误“预期的声明或语句”
如何从一个非常简单的ts文件中导出一个函数,以便能够在另一个ts文件中使用该函数?
发布于 2017-02-02 11:00:33
看起来
let myfunction = something that returns a function
export {myfunction};就能达到目的。
发布于 2018-06-05 18:31:22
使用
export default myfunction如果只有这个函数可以从这个文件中导出。否则请使用
export { myfunction, <other exports> }导出myfunction和要导出的其他类型的步骤
发布于 2017-02-02 10:56:38
您可以使用模块化的顶级import和export声明从另一个文件调用function或实例化class。
文件1.ts
// This file is an external module because it contains a top-level 'export'
export function foo() {
console.log('hello');
}
export class bar { }文件2.ts
// This file is also an external module because it has an 'import' declaration
import f1 = module('file1');
f1.foo();
var b = new f1.bar();https://stackoverflow.com/questions/41993445
复制相似问题