TypeScript: access to a static class method

Still new in TypeScript, so this question may seem silly to some of you. I have a ToolTip class, for example:

class ToolTip{ public static show (str:string):void{ console.log ("ToolTip show():" + str); } public static hide():void{ console.log ("ToolTip hide()"); } } export = ToolTip; 

And I want to call it from another class

 import ToolTip = require ("app/view/common/Tooltip"); class Button { ...... private handleMouseEvent(event:MouseEvent):void { switch (event.type) { case "mouseover": ToolTip.show("tool tip string"); break; case "mouseout": ToolTip.hide(); break; } } ...... } export = MenuItem; 

But this gives me this error:

 Uncaught TypeError: Object app/view/common/Tooltip has no method 'show' 

Any idea how to fix this?

+7
static typescript
source share
1 answer

As you can see, the code works fine (compiles and runs):

enter image description here

Possible reasons why this would not work for you:

  • You did not compile with the --module commonjs ( Video tutorial )
  • You have a folder named TootTip at the same level as Tooltip.ts , which could cause nodejs to run something you might not expect.
+3
source share

All Articles