[syntax] Can typescript export a function?

Is it possible to export a simple function from a typescript module?

This isn't compiling for me.

module SayHi {
    export function() {
    console.log("Hi");
  }
}
new SayHi();

This workitem seems to imply that you cannot but doesn't flat out say it. Is it not possible?

This question is related to syntax typescript

The answer is


If you are using this for Angular, then export a function via a named export. Such as:

function someFunc(){}

export { someFunc as someFuncName }

otherwise, Angular will complain that object is not a function.


In my case I'm doing it like this:

 module SayHi {
    export default () => { console.log("Hi"); }
 }
 new SayHi();

To answer the title of your question directly because this comes up in Google first:

YES, TypeScript can export a function!

Here is a direct quote from the TS Documentation:

"Any declaration (such as a variable, function, class, type alias, or interface) can be exported by adding the export keyword."

Reference Link