I have a node app that has a string of requires, like this:
var express = require('express'),
router = require('./router'),
data = require('./data');
This code works without changes, but how can I take full advantage of TypeScript modules? Just using
import data = module("./data")
will tell me
The name ”./data” does not exist in the current scope
How can I import an external file with TypeScript?
The example,
contains a file called
node.d.tswhich shows how to declare the types for an existing node.js module.TypeScript requires the module be declared for you use to
importsyntax. This is typically provided in a.d.tsfile but can be included in the same file. An example this might look like,In a
.d.tsfile thedeclarekeywords is implied and can be omitted.