Property 'Server' does not exist on type &

2019-07-14 03:45发布

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条回答
【Aperson】
2楼-- · 2019-07-14 04:10

Try this:

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

This might help.

Clarification: You are using default import instead named import.

查看更多
登录 后发表回答