Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are typescript type definitions required?

Tags:

typescript

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

like image 414
kimsagro Avatar asked Dec 09 '15 01:12

kimsagro


1 Answers

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.

like image 147
basarat Avatar answered Oct 20 '22 05:10

basarat