我有以下代码:
export const makeHttpHelper = function (authToken: string) {
return function ($data: any, optz: object, cb: VoidFn) {
const data = JSON.stringify($data || '\n');
const opts : http.Request.options = Object.assign({ /// <<<< here <<<<<<
method: 'POST',
host: process.env.OPENSHIFT_NODEJS_IP || 'localhost',
port: process.env.OPENSHIFT_NODEJS_PORT || '3040',
agent: false,
headers: getHeaders()
}, optz);
const req = http.request(opts, function (res) {
if (res.statusCode > 202) {
log.error(`res status => ${res.statusMessage}, ${res.statusCode}, req url => ${opts.url || opts.path}`);
}
else {
log.info(`res status => ${res.statusMessage}, ${res.statusCode}, req url => ${opts.url || opts.path}`);
}
// ....
});
....问题是http.Request.options
不正确。有没有人知道作为http.request()
的第一个参数的选项对象的正确类型是什么?
答案 0 :(得分:1)
http.Request.options不正确
正确的是http.RequestOptions
。
修正:
import * as http from 'http';
const options: http.RequestOptions = { // Fixed
}
http.request(options, /* other */)