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
basarat was correct about the typings
property. See Typings for npm packages for more information
It appears that the definition files are required, is this always the case?
No. If the module does it properly using the typings
property it would just work. More: https://basarat.gitbooks.io/typescript/content/docs/quick/nodejs.html
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?
Only if they have typings
setup properly ... which they don't.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With