0

I'm using TypeScript in VS2015, and trying to import the knockout module in some other module. Knockout is installed to a path other than "/knockout", in fact, all my "libraries" are installed to "/app/lib". As a result of the folder names not necessarily matching the module names, I've defined the following in my main.ts:

requirejs.config({
    baseUrl: "/app",
    paths: {
        "text"       : "lib/requirejs-text/text",
        "durandal"   : "lib/durandal/js",
        "plugins"    : "lib/durandal/js/plugins",
        "transitions": "lib/durandal/js/transitions",
        "knockout"   : "lib/knockout.js/knockout",
        "jquery"     : "lib/jquery/jquery",
        "bootstrap"  : "lib/bootstrap-sass-official/javascript/bootstrap"
    }
});

So my app at runtime can find knockout using just var ko = require("knockout").

However, at design time in visual studio, I get a "red squiggly" under my require() call:

enter image description here

I believe this is because VS is trying to use paths rather than my custom path configuration to look for Knockout. How then, can I tell VS about my custom path configuration so this works? At the moment the generated JavaScript is:

var receiveDeliveryViewModel = (function () {
    function receiveDeliveryViewModel() {
        this.deliveryReference = ("");
    }
    return receiveDeliveryViewModel;
})();

Which as you can see does not reference Knockout.js.

Many thanks in advance.

1 Answer 1

1

You need to add the type definition for Knockout:

This will provide type information for Knockout and also solve the import error you are seeing.

Also available via NuGet (other package managers are available)!

Sign up to request clarification or add additional context in comments.

Comments

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.