Exporting a function in typescript "declaration or statement pending"

I understand this is really simple, but typescript seems to have changed a lot in recent years, and I just can't do it with the previous answers I found here when the stack overflowed.

let myfunction = something that returns a function export myfunction; 

I get an error message or expected message "

How can I export a function from a really simple ts file to be able to use this function in another ts file?

+5
source share
2 answers

It seems that

 let myfunction = something that returns a function export {myfunction}; 

will do the trick.

+17
source

You can call function or instantiate a class from another file using the top-level modular declarations import and export .

file1.ts

 // This file is an external module because it contains a top-level 'export' export function foo() { console.log('hello'); } export class bar { } 

file2.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(); 
0
source

Source: https://habr.com/ru/post/1263710/


All Articles