8

I am using knockout js in my simple application. knockout js works fine in my application. My problems is why VS 2013 or WebStorm does not show any intellisense for knockout? Also it shows intellisense for jQuery.

Currently my codes is :

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <script src="Scripts/jquery-1.9.0.js"></script>
    <script type="text/javascript" src="Scripts/knockout-3.0.0.js"></script>
    <script type="text/javascript">
        $(function() {
            $("#jqueryTestId").html("Hello world, From jquery.");
        });
    </script>
</head>
<body>
    <div>
        name: <input type="text" data-bind="value: name"/> <br/>
        You've clicked <span data-bind="text: numberOfClicks"></span> times
        <button data-bind="click: incrementClickCounter">Click me</button>

    </div>
    <div id="jqueryTestId">

    </div>

<script type="text/javascript">
    var viewModel = {
        numberOfClicks : ko.observable(0),
        name : ko.observable(""),
        incrementClickCounter : function() {
            var previousCount = this.numberOfClicks();
            alert(this.name("TestName"));
            this.numberOfClicks(previousCount + 1);
        }
    };

    ko.applyBindings(viewModel);
</script>
</body>
</html>

In WebStorm it does not show any intellisense. But in VS 2013 it only shows ko in suggested list, but does not show observable function like:

ko.observable();

How I can enable intellisense?

wonea
  • 4,783
  • 17
  • 86
  • 139
Seyed Morteza Mousavi
  • 6,855
  • 8
  • 43
  • 69
  • possible duplicate of [Intellisense doesn't work for JS in VS2013](http://stackoverflow.com/questions/20232803/intellisense-doesnt-work-for-js-in-vs2013) – PW Kad Feb 01 '14 at 23:03
  • @PWKad i test VS for jQuery but its intellisense works fine – Seyed Morteza Mousavi Feb 02 '14 at 07:34
  • 2
    For WebStorm, your best bet is to configure Knockout as a library like: http://www.jetbrains.com/webstorm/webhelp/configuring-javascript-libraries.html. From the Libraries dialog, click Download..., then switch the dropdown to "TypeScript community stubs", and pick the Knockout one. This will give you the best intellisense. – RP Niemeyer Feb 02 '14 at 17:53

2 Answers2

8

You just have to use the debug version of KnockoutJS i did and it autocompleted very well:

<script type="text/javascript" src="js/knockout-3.2.0.debug.js"/>

Knockout Debug Version

Hope this Fix your problem :)

Also this works well for "data-bind" tags: link

Eefret
  • 4,724
  • 4
  • 30
  • 46
  • This solved the intellisense issue for RubyMine as well. – Ryan Rodemoyer Sep 27 '14 at 12:19
  • 1
    While this indeed solves the issue, I am not 100% happy following the note you can find at knockout official website (check the part in bold): _Also available: debug build. Note: This is only intended to help you understand how Knockout works. **Don't use it for normal application development, because it exposes additional unsupported private APIs.**_ It would be nice if either knockout is written in a way intellisense is easier or other IDE's adapt to the way knockout declares its code. – CGodo Apr 08 '16 at 11:54
  • I agree with you as the debug script is also bigger, but if you use it only for the sake of the intellisense autocomplete, I think its fair to change back and forth from the minified to the debug version. – Eefret Apr 11 '16 at 15:36
  • I think it's possible to keep the debug script out of your main source directory and still get the code completion benefits. I'm not actually using the debug script in any script tag but Webstorm still picks up the library for indexing. – nath May 13 '16 at 09:38
1

Using knockout.d.ts configured as a javascript library in Settings/libraries/javaScript, as @RP Niemeyer has suggested, is the best solution for WebStorm. Using minified knockout-3.0.0.js as a library doesn't currently work - see WEB-10723

lena
  • 90,154
  • 11
  • 145
  • 150