WorkingMatt WorkingMatt - 4 months ago 76
TypeScript Question

Typescript: Getting started problems (Cannot find module fs and cannot find name typings)

I am getting to grips with Typescript. I am having issues with using fs.

The following code produces this error:

Ingest.ts(4,21): error TS2307: Cannot find module 'fs'

// <reference path="typings/node/node.d.ts"/>
'use strict';

import * as fs from "fs";

console.log("hi matt");
var data = fs.readFileSync('matt.txt');

When I change the first line to /// rather than //

I get this error:

typings/node/node.d.ts(512,16): error TS2304: Cannot find name 'IterableIterator'.
typings/node/node.d.ts(514,13): error TS2304: Cannot find name 'IterableIterator'.
typings/node/node.d.ts(515,15): error TS2304: Cannot find name 'IterableIterator'.

Prior to trying these I had done these steps:

npm install -g typescript
npm install -g tsd@next
cd <project folder>
tsd install node
tsc -init
tsc Ingest.ts

Node v.6.4.0 and tsc v.1.8.10 on OSX Yosemite


OK, a few things here. TSD is done, use typings instead npm install -g typings. With typings, you need to know the repository for the type files, it will be one of the columns returned when you do a typings search <package>. I've had most of my type files come from the DefinitelyTyped repo. To install a package from there, you do typings install dt~<package>.

Second, you error with the IterableIterator, I've already reported this to the Node type team, they are working on a resolution for it, but you can get around it in the mean time by installing the core-js types typings install dt~core-js --global