'typeof“http”'类型中不存在属性'Server'

时间:2017-06-05 21:05:08

标签: javascript node.js typescript socket.io ecmascript-6

我知道<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.1.2" /> 通常被var someModule = require('someModule')取代但我无法弄清楚如何使用Typescript / ES6语法来表达以下Node.js代码:

import * as someModule from 'someModule'

阅读import and call a function with es6后 我尝试过以下方法:

var server = require('http').Server(app);

并且代码确实编译并正常运行,但我仍然遇到此TS错误:

import * as httpModule from 'http'; const server = httpModule.Server(app);

我安装了@ types / node和@ types / express。我错过了什么吗?

1 个答案:

答案 0 :(得分:2)

试试这个:

import { Server, createServer } from 'http';
const server = createServer(app);

This might help

澄清:您正在使用default import instead named import