My understanding of typescript definition files is that they are used to provide tooling support and are not required to compile typescript.
However given the following:
app.ts
import {Observable} from 'rx';
Observable
.interval(1000)
.subscribe(n => console.log(n));
Running:
npm install typescript rx --save
.\node_modules\.bin\tsc app.ts --module commonjs
Gives the error:
app.ts(1,26): error TS2307: Cannot find module 'rx'.
Import the type definitions for rx fixes this
app.ts
/// <reference path="./node_modules/rx/ts/rx.all.d.ts" />
import {Observable} from 'rx';
Observable
.interval(1000)
.subscribe(n => console.log(n));
Questions
- It appears that the definition files are required, is this always the case?
- The rx npm package includes the definition files. Can typescript automatically search the node modules folder to find them without me having to explicitly reference them?
Update
basarat was correct about the typings
property. See Typings for npm packages for more information