1

New to TypeScript, please let me know if something is left out ... Okay here is my complete code:

/// <reference path="typings/knockout.d.ts" />

declare var ko: any; 

module test {

    var name = ko.observable('John Dude');
    var id = ko.observable(1);
    var guy = {
        id: id,
        fullName: name
    };

    var value: string = guy.fullName();
    console.log(value);
}

The problem is ... I get this message, something about this line

declare var ko: any;

and here is the actual message

TypeScript declaration error ...

I have no idea how to fix it, tried pretty much everything! ... no idea why

1 Answer 1

1

If you've included knockout.d.ts, you no longer need the line declare var ko: any; as the .d.ts file has already defined the shape of ko for you. The compiler is warning you that you're declaring ko with two different types (any, and the more complex type defined in the .d.ts file).

Simply remove that line of code.

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

3 Comments

Yes, I have tried that. When I do remove it like you mention I get the following in Google chrome dev tools. [Uncaught ReferenceError: ko is not defined] What do I do now?
You need to include knockout.js in a script tag (above the script tag that includes your .js file) in your HTML
Also there was some other library that was interfering, but after this, "you no longer need the line declare var ko: any;" was able to troubleshoot it and fixed it. Thank you.

Your Answer

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