“绝对键入" NodeJS + Express定义文件有错误 [英] "Definitely typed" NodeJS + Express definition file has errors

查看:96
本文介绍了“绝对键入" NodeJS + Express定义文件有错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将具有NodeJS + ExpressJS的项目转换为Typescript.

I am trying to convert my project that has NodeJS + ExpressJS to Typescript.

我从绝对类型"中获得了定义文件,但是它们似乎有很多错误:

I got the definition files from Definitely Typed, but they seem to have plenty of errors:

export interface ClientRequest extends events.NodeEventEmitter, stream.WritableStream    
{
    // Extended base methods
    write(str: string, encoding?: string, fd?: string): boolean;
    write(buffer: NodeBuffer): boolean;

    write(chunk: any, encoding?: string): void;
    end(data?: any, encoding?: string): void;
    abort(): void;
    setTimeout(timeout: number, callback?: Function): void;
    setNoDelay(noDelay?: Function): void;
    setSocketKeepAlive(enable?: boolean, initialDelay?: number): void;
}

export interface Server extends net.Server {
    // Extended base methods
    listen(port: number, host?: string, backlog?: number, listeningListener?: Function): void;
    listen(path: string, listeningListener?: Function): void;
    listen(handle: any, listeningListener?: Function): void;

    listen(port: number, host?: string, callback?: Function): void;
    close(): void;
    address(): { port: number; family: string; address: string; };
    addContext(hostName: string, credentials: {
        key: string;
        cert: string;
        ca: string;
    }): void;
    maxConnections: number;
    connections: number;
}

方法写入"和侦听会引发错误:对可写流成员的重写不兼容".

The methods "write" and listen throw the error: "Incompatible override for member of writable stream".

在app.js文件中,var app = express();函数引发错误:方法表达式不是函数类型:

In the app.js file the var app = express(); function throws an error: Method expression is not a function type:

var http = require("http");
var express = require("express");
var expose = require("express-expose");
var fs = require("fs");
var formidable = require("formidable");
var upload = require('Upload');

var app = express();
var HOST = "localhost";
var PORT = 8080;

推荐答案

不兼容的覆盖"-这是webStorm中的错误,请投票给

'incompatible override' - it's a bug in webStorm, please vote for WEB-10239

方法表达式不是函数类型:"无法在WebStorm 7.0.2中重现

'Method expression is not a function type:' can't reproduce in WebStorm 7.0.2

这篇关于“绝对键入" NodeJS + Express定义文件有错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆