I an using Visual Studio 2013 tools for Node.js with VS2013 Update 2.
I have the following code in a util.ts file:
var Util = function () {
this.getSelectOption = function (elem, value) {
var x = 99;
}
module.exports = new Util();
and then in a base.ts file
// <reference path="../../Utils/util.ts" />
// <reference path="../../Utils/helpers.ts" />
var util = require('../../Utils/util.js');
When I hover over util then all I see is
(var) util: any
Can someone explain to me what might be wrong. I was expecting Typescript to be able to pick up the definition of the getSelectOption function?
You need to use TypeScript's import/export statements and not the standard commonjs pattern (var / require).
Also you will need to compile with the --module commonjs flag.
More : https://www.youtube.com/watch?v=KDrWLMUY0R0&hd=1
First file. Use a TypeScript container for your function. Like a module or a class. Also use export
module Util {
export function getSelectOption (elem, value) {
var x = 99;
}
}
export = Util;
other file (use import, no need for .js extension):
import util = require('../../Utils/util');
TypeScript supports both AMD + CommonJS targets with the SAME TypeScript code. And therefore extends the language to find a common ground to support them.