Friday 15 August 2014

syntax - Can typescript export a function? -


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

  Module SayHi {export function () {console.log ("Hi"); }} New Sahi ();   

It seems that you can not do that but it is not possible to say that it is not possible?

It's hard to say what you are doing in that example. About exporting export = , External module, but the link code sample you have is internal module.

Rule Thumbs: If you type the module foo {...} , then you are writing an internal module; If you type export something at the top-level in the file, then you are writing an external module. It is rare that you actually get the export module foo the top-level (Since then you want to repeat the name), and it is also rare that you have module foo in a file that had a top-level export (since foo Externally not visible)

The following things are understood (horizontal rules as illustrated by each scenario):


  // exported function 'Foo' module SayHi {export function foo () {Console.log ("hi") with an internal module called SayHi; } Export class bar {}} // N.B. This line can be in another file with a //   

file1.ts

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

file2.ts

  // This file is also an external module because it contains a ' Import 'announcement import f1 = module (' file1 '); F1.foo (); Var b = new f1.bar ();   

file1.ts

  // This will only work in 0.9.0+. This file is an external / / module because it has a top-level 'export' function f () {} function g () {} export = {alpha: f, beta: g};   

file2.ts

  // This file is also an external module because it has an 'import' declaration import f1 = Required ('file1'); F1.alpha (); // inv f f1.beta (); // invokes    

No comments:

Post a Comment