我正在将NodeJS + ExpressJS项目转换为打字稿,我从https://github.com/borisyankov/DefinitelyTyped获得了ExpressJS的Typescript定义。
在打字稿之前我使用“require”语句导入Express
var express = require("express")
不,我需要以可以使用Typescript语法和功能的方式导入它,同时确保Typescript编译器将其编译为上面显示的语句。这是我写的代码:
/// <reference path="express.d.ts" />
import express = require("express");
var app = express.express();
app.use(express.logger());
然而,这会引发错误:Unresolved function or method express()
at:
var app = express.express();
答案 0 :(得分:4)
我认为应该是:
import express = require('express');
var app = express();
参见示例:https://github.com/borisyankov/DefinitelyTyped/blob/master/express/express-tests.ts#L3-L4