I'm new with Typescript and with NodeJS.
For some reason this:
GetMenuDataCommand.ts
"use strict";
import fs = module("fs")
becomes this:
GetMenuDataCommand.js
var fs = "fs";
Typescript - i love you - but why?
I'm using TypeScript 0.9 the following code:
/// <reference path="node.d.ts" />
import fs = require("fs");
fs.appendFile('name.txt', 'Some data');
Produces the following identical output:
var fs = require("fs");
fs.appendFile('name.txt', 'Some data');
(In CommonJS mode - in AMD mode it does the below...)
define(["require", "exports", "fs"], function(require, exports, __fs__) {
var fs = __fs__;
fs.appendFile('name.txt', 'Some data');
});
Are you referencing the node.d.ts file correctly? If TypeScript doesn't have a reference to the definition file for your import, it'll generate a string for the import instead of the expected code.
For example, I had the following:
import passport = require('passport');
and that was generating:
var passport = "passport";
Turns out I'd forgotten to reference the definition file. Adding a reference at the top of the file solved the problem:
/// <reference path="../../definitions/passport.d.ts" />
Arguably you should spot it easily because the TypeScript compiler would throw an error, but 0.9.x is somewhat bug-ridden and it doesn't always catch everything.
Not sure if its related but in ts 0.9.x use require instead of module keyword :
"use strict";
import fs = require("fs")