Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exporting a function on typescript "declaration or statement expected"

Tags:

typescript

I realize this is really simple but typescript seems to have changed a lot in the last years and i just cant get this done with previous answers i found here on stack overflow.

let myfunction = something that returns a function  export myfunction; 

I get an error "declaration or statement expected"

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

like image 728
Joaquin Brandan Avatar asked Feb 02 '17 02:02

Joaquin Brandan


2 Answers

It seems that

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

will do the trick.

like image 89
Joaquin Brandan Avatar answered Sep 16 '22 12:09

Joaquin Brandan


Use

export default myfunction 

if you only have this function to export from this file. Otherwise use

export { myfunction, <other exports> } 

to export myfunction along with other types to export

like image 35
Philip Bijker Avatar answered Sep 20 '22 12:09

Philip Bijker