Am I getting this right?
tsc
Its the typescript cli tool and the global version running on my machine.
typings
typings is a few things. A cli tool to install .d.ts files into your project AND the folder that save to inside my project.
For example:
you can search for .d.ts scripts by running:
typings search foo
and add a package:
typings install --global --save dt~foo
then have the typings/index.d.ts
reference all my .d.ts
definition files
/// <reference path="globals/foo/index.d.ts" />
Then if I wanted to use foo
anywhere in my project I could add
declare var foo: any;
import foo from "foo";
Definitely Types
Definitely Types files have a .d.ts extension that allow javascript methods to be called in Typescript
@typings
Is a folder located at node_modules/@typings
and is the same as the typings
folder, but are installed by running npm install @typings/foo
and not typings install foo
.
My questions are:
why are there two different ways to install typings do this? Is the first method a depreciated method of including Definitely Types files to my project?
Are @typings
module still searchable by running?
typings search foo
How are I make my project aware of my typings
, did defining them like /// <reference path="globals/foo/index.d.ts" />
get scrapped?
Do I always/when do I declare my .d.ts files in my project like declare var foo: any;
Do you still need to use the ambient
or global
flags when installing?
This was a little confusing for me as well as I've spent the last couple months familiarizing with TypeScript...
tsc
Correct, this is the TypeScript Compiler which translates your files to JavaScript.
Typings
Typings is a cli TypeScript definitions manager which allows you to manage (search, install, uninstall, etc.) definition files (*.d.ts) for JavaScript libraries from a variety of sources.
DefinitelyTyped
DefinitelyTyped is a repository of definition files which is one of the sources that Typings allows you to gather/manage files from.
npm @types
The good news is with latest release of TypeScript (version 2.0+) you no longer need to use a manager and/or worry about which repositories to gather files from. All of the definitions from DefinitelyTyped are now available to install via npm (example: npm install @types/knockout --save
).
Using this method will download the definition file, save the dependency in your project.json file (if the --save flag is specified) which TypeScript then automatically looks for the definition whenever you require()
the module within your code (you no longer need to use /// <reference />
if you use this method).
The TypeScript website has pretty extensive documentation on project setup and how to use tsconfig.json files to properly setup your application for compilation with or without definition files.