我正在尝试将具有NodeJS + ExpressJS的项目转换为Typescript。
我从Definitely Typed获得定义文件,但它们似乎有很多错误:
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;
}
方法“write”和listen抛出错误:“不可写的覆盖成员的可写流”。
在app.js文件中,var app = express();
函数抛出错误:方法表达式不是函数类型:
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;