【问题标题】:HTTP Request options - TypeScript valueHTTP 请求选项 - TypeScript 值
【发布时间】:2018-09-04 02:49:10
【问题描述】:

我有以下代码:

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() 第一个参数的选项对象的正确类型是什么?

【问题讨论】:

    标签: node.js typescript typescript-typings typescript2.0


    【解决方案1】:

    http.Request.options 不正确

    正确的是http.RequestOptions

    固定:

    import * as http from 'http';
    const options: http.RequestOptions = { // Fixed
    
    }
    http.request(options, /* other */)
    

    【讨论】:

      猜你喜欢
      • 2012-06-21
      • 2018-01-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-10
      • 2017-05-05
      相关资源
      最近更新 更多