Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeScript: access static method of a class

Still new at TypeScript so this question may sound dumb to some of you. I have a ToolTip class like this:

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 it gives me this error:

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

Any idea how to fix this?

like image 892
DT DT Avatar asked Sep 06 '13 16:09

DT DT


1 Answers

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

enter image description here

So possible reasons why it would not work for you :

  • You did not compile with the --module commonjs option (Video Tutorial)
  • You have a folder named TootTip at the same level as Tooltip.ts which can cause nodejs to run what you might not have expected.
like image 185
basarat Avatar answered Nov 10 '22 12:11

basarat