Property 'Server' does not exist on type 'typeof “http”'

我们两清 提交于 2019-12-24 05:37:35

问题


I know that var someModule = require('someModule') is generally replaced by import * as someModule from 'someModule' but I can't figure out how to use Typescript/ES6 syntax to express the following Node.js code:

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

After reading import and call a function with es6 I have tried the following:

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

and the code does compile and run properly but I still get this TS error:

[ts] Property 'Server' does not exist on type 'typeof "http"'.

I have @types/node and @types/express installed. Am I missing something?


回答1:


Try this:

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

This might help.

Clarification: You are using default import instead named import.



来源:https://stackoverflow.com/questions/44377686/property-server-does-not-exist-on-type-typeof-http

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!