From d1fe542d52898442c1afe26da8d6d2dcafd2dd64 Mon Sep 17 00:00:00 2001 From: Kevin Greene Date: Fri, 27 Oct 2017 10:05:05 -0700 Subject: [PATCH] Account for 'set-cookie' header in Node v8 types --- types/node/index.d.ts | 12 +++++++++--- types/node/node-tests.ts | 21 ++++++++++++++++++--- types/node/v4/index.d.ts | 20 +++++++++++--------- types/node/v4/node-tests.ts | 23 +++++++++++++++++------ types/node/v6/index.d.ts | 20 +++++++++++--------- types/node/v6/node-tests.ts | 23 +++++++++++++++++------ types/node/v7/index.d.ts | 20 +++++++++++--------- types/node/v7/node-tests.ts | 23 +++++++++++++++++------ 8 files changed, 111 insertions(+), 51 deletions(-) diff --git a/types/node/index.d.ts b/types/node/index.d.ts index d8e8fe3358..419e09d667 100644 --- a/types/node/index.d.ts +++ b/types/node/index.d.ts @@ -836,14 +836,20 @@ declare module "http" { import * as stream from "stream"; import { URL } from "url"; - // incoming headers will never contain number - export interface IncomingHttpHeaders { + export interface BaseIncomingHttpHeaders { [header: string]: string | string[]; } + export interface SetCookieHttpHeader { + 'set-cookie'?: string[]; + } + + // incoming headers will never contain number + export type IncomingHttpHeaders = BaseIncomingHttpHeaders & SetCookieHttpHeader; + // outgoing headers allows numbers (as they are converted internally to strings) export interface OutgoingHttpHeaders { - [header: string]: number | string | string[] | undefined; + [header: string]: number | string | string[]; } export interface ClientRequestArgs { diff --git a/types/node/node-tests.ts b/types/node/node-tests.ts index c4cd693e03..e75059eea4 100644 --- a/types/node/node-tests.ts +++ b/types/node/node-tests.ts @@ -1316,9 +1316,24 @@ namespace http_tests { request.abort(); } - const options: http.RequestOptions = { - timeout: 30000 - }; + // http request options + { + const requestOpts: http.RequestOptions = { + timeout: 30000 + }; + + const clientArgs: http.ClientRequestArgs = { + timeout: 30000 + }; + } + + // http headers + { + const headers: http.IncomingHttpHeaders = { + 'Content-Type': 'application/json', + 'set-cookie': [ 'type=ninja', 'language=javascript' ] + }; + } } ////////////////////////////////////////////////////// diff --git a/types/node/v4/index.d.ts b/types/node/v4/index.d.ts index 431cb7d07c..792537be95 100644 --- a/types/node/v4/index.d.ts +++ b/types/node/v4/index.d.ts @@ -557,18 +557,20 @@ declare module "http" { import * as net from "net"; import * as stream from "stream"; - // incoming headers will never contain number - export type IncomingHttpHeaders = { - [header: string]: string - } & { - 'set-cookie'?: string[] + export interface BaseIncomingHttpHeaders { + [header: string]: string | string[]; } + export interface SetCookieHttpHeader { + 'set-cookie'?: string[]; + } + + // incoming headers will never contain number + export type IncomingHttpHeaders = BaseIncomingHttpHeaders & SetCookieHttpHeader; + // outgoing headers allows numbers (as they are converted internally to strings) - export type OutgoingHttpHeaders = { - [header: string]: number | string - } & { - 'set-cookie'?: string[] + export interface OutgoingHttpHeaders { + [header: string]: number | string | string[]; } export interface RequestOptions { diff --git a/types/node/v4/node-tests.ts b/types/node/v4/node-tests.ts index 3ba0db2851..1cca96f708 100644 --- a/types/node/v4/node-tests.ts +++ b/types/node/v4/node-tests.ts @@ -500,13 +500,24 @@ namespace http_tests { request.abort(); } - const reqOptions: http.RequestOptions = { - timeout: 30000 - }; + // http request options + { + const requestOpts: http.RequestOptions = { + timeout: 30000 + }; - const clientArgs: http.ClientRequestArgs = { - timeout: 30000 - }; + const clientArgs: http.ClientRequestArgs = { + timeout: 30000 + }; + } + + // http headers + { + const headers: http.IncomingHttpHeaders = { + 'Content-Type': 'application/json', + 'set-cookie': [ 'type=ninja', 'language=javascript' ] + }; + } } ////////////////////////////////////////////////////// diff --git a/types/node/v6/index.d.ts b/types/node/v6/index.d.ts index a6d3d54b5b..0dd86fc790 100644 --- a/types/node/v6/index.d.ts +++ b/types/node/v6/index.d.ts @@ -629,18 +629,20 @@ declare module "http" { import * as net from "net"; import * as stream from "stream"; - // incoming headers will never contain number - export type IncomingHttpHeaders = { - [header: string]: string - } & { - 'set-cookie'?: string[] + export interface BaseIncomingHttpHeaders { + [header: string]: string | string[]; } + export interface SetCookieHttpHeader { + 'set-cookie'?: string[]; + } + + // incoming headers will never contain number + export type IncomingHttpHeaders = BaseIncomingHttpHeaders & SetCookieHttpHeader; + // outgoing headers allows numbers (as they are converted internally to strings) - export type OutgoingHttpHeaders = { - [header: string]: number | string - } & { - 'set-cookie'?: string[] + export interface OutgoingHttpHeaders { + [header: string]: number | string | string[]; } export interface RequestOptions { diff --git a/types/node/v6/node-tests.ts b/types/node/v6/node-tests.ts index c3cced9921..30f14e3c90 100644 --- a/types/node/v6/node-tests.ts +++ b/types/node/v6/node-tests.ts @@ -936,13 +936,24 @@ namespace http_tests { request.abort(); } - const reqOptions: http.RequestOptions = { - timeout: 30000 - }; + // http request options + { + const requestOpts: http.RequestOptions = { + timeout: 30000 + }; - const clientArgs: http.ClientRequestArgs = { - timeout: 30000 - }; + const clientArgs: http.ClientRequestArgs = { + timeout: 30000 + }; + } + + // http headers + { + const headers: http.IncomingHttpHeaders = { + 'Content-Type': 'application/json', + 'set-cookie': [ 'type=ninja', 'language=javascript' ] + }; + } } ////////////////////////////////////////////////////// diff --git a/types/node/v7/index.d.ts b/types/node/v7/index.d.ts index fae6d5700e..e67dfdc969 100644 --- a/types/node/v7/index.d.ts +++ b/types/node/v7/index.d.ts @@ -646,18 +646,20 @@ declare module "http" { import * as net from "net"; import * as stream from "stream"; - // incoming headers will never contain number - export type IncomingHttpHeaders = { - [header: string]: string - } & { - 'set-cookie'?: string[] + export interface BaseIncomingHttpHeaders { + [header: string]: string | string[]; } + export interface SetCookieHttpHeader { + 'set-cookie'?: string[]; + } + + // incoming headers will never contain number + export type IncomingHttpHeaders = BaseIncomingHttpHeaders & SetCookieHttpHeader; + // outgoing headers allows numbers (as they are converted internally to strings) - export type OutgoingHttpHeaders = { - [header: string]: number | string - } & { - 'set-cookie'?: string[] + export interface OutgoingHttpHeaders { + [header: string]: number | string | string[]; } export interface RequestOptions { diff --git a/types/node/v7/node-tests.ts b/types/node/v7/node-tests.ts index 89f49817c7..8b64371d4d 100644 --- a/types/node/v7/node-tests.ts +++ b/types/node/v7/node-tests.ts @@ -1033,13 +1033,24 @@ namespace http_tests { request.abort(); } - const reqOptions: http.RequestOptions = { - timeout: 30000 - }; + // http request options + { + const requestOpts: http.RequestOptions = { + timeout: 30000 + }; - const clientArgs: http.ClientRequestArgs = { - timeout: 30000 - }; + const clientArgs: http.ClientRequestArgs = { + timeout: 30000 + }; + } + + // http headers + { + const headers: http.IncomingHttpHeaders = { + 'Content-Type': 'application/json', + 'set-cookie': [ 'type=ninja', 'language=javascript' ] + }; + } } //////////////////////////////////////////////////////