xBodro
xBodro

Reputation: 61

Typescript Type Definition References

I have a project with multiple typescript files. If I add a new typescript file I have to reference typings in order to compile it, VS couldn't resolve them itself. Also I have empty .ts file that doesn't require referencing typings, so I put code into it and it works.

When I found out it I kept the file and now when I need to create new .ts file, I copy that file and everything works like a charm.

So suppose in a folder I have two .ts files side by side: a copy of a magic file and a newly created one.

If I put this code in the magic file

class Test {
    test: KnockoutObservable<string>;
}

it compiles. If I put the same code into another file it says

Cannot find name KnockoutObservable

What is so special about the first file?

I'm using Visual Studio 2015. I have installed Knockout typings. I have empty tsconfig.json file in the solution. I don't want to reference typings using /// reference comment.

Thanks.

Upvotes: 1

Views: 705

Answers (1)

TSV
TSV

Reputation: 7641

You need to use TSD and install appropriate ".d.ts" file, e.g. for knockout:

tsd install knockout

It downloads "knockout.d.ts" into your project and places definition into typings folder:

typings/knockout/knockout.d.ts 

Then you can add corresponding reference to the top or your "ts" file. e.g.:

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

Upvotes: 1

Related Questions