9

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?

4
  • This works for me. Are you using 0.9.1.1? Commented Sep 6, 2013 at 16:20
  • I am using 0.9.1.1 too, using Webstorm EAP to compile it Commented Sep 6, 2013 at 17:17
  • I don't think Webstorm automatically picks up the latest TypeScript compiler. Can you reproduce the problem using tsc.exe ? Commented Sep 6, 2013 at 18:11
  • but this is a run time error, not at compile time. Commented Sep 6, 2013 at 19:18

1 Answer 1

6

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.
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you guys, I have found the error. When I change the file name from "Tooltip" to "ToolTip", the javascript never get updated, so it looks for Tooltip.js instead of ToolTip.js.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.