From dd0d4ad0c415d008900312a443bc1c4fadea11db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Astori?= Date: Thu, 3 May 2018 11:57:27 -0400 Subject: [PATCH] Type spawn's args as a ReadonlyArray of string (#25487) At the moment, this snippet: ```ts const spawnArgs: ReadonlyArray = ['foo', 'bar']; spawn('foobar', spawnArgs); ``` fails with: ``` Argument of type 'ReadonlyArray' is not assignable to parameter of type 'string[] | undefined'. Type 'ReadonlyArray' is not assignable to type 'string[]'. ``` Looking at https://github.com/nodejs/node/blob/master/lib/child_process.js#L514-L535 and https://github.com/nodejs/node/blob/master/lib/internal/child_process.js#L286, it _looks_ like there is no mutation of the array. I am no expert so I'd be happy to be proven wrong, I just couldn't find sufficient evidence that a `ReadonlyArray` wouldn't be fine. This is not a breaking change because passing a `string[]` is still valid. --- types/node/index.d.ts | 2 +- types/node/v0/index.d.ts | 2 +- types/node/v4/index.d.ts | 2 +- types/node/v6/index.d.ts | 2 +- types/node/v7/index.d.ts | 2 +- types/node/v8/index.d.ts | 2 +- types/node/v9/index.d.ts | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/types/node/index.d.ts b/types/node/index.d.ts index b545ec718e..9ba96612dc 100644 --- a/types/node/index.d.ts +++ b/types/node/index.d.ts @@ -2101,7 +2101,7 @@ declare module "child_process" { windowsHide?: boolean; } - export function spawn(command: string, args?: string[], options?: SpawnOptions): ChildProcess; + export function spawn(command: string, args?: ReadonlyArray, options?: SpawnOptions): ChildProcess; export interface ExecOptions { cwd?: string; diff --git a/types/node/v0/index.d.ts b/types/node/v0/index.d.ts index ef1c485d2d..37f92cbc50 100644 --- a/types/node/v0/index.d.ts +++ b/types/node/v0/index.d.ts @@ -881,7 +881,7 @@ declare module "child_process" { unref(): void; } - export function spawn(command: string, args?: string[], options?: { + export function spawn(command: string, args?: ReadonlyArray, options?: { cwd?: string; stdio?: any; custom?: any; diff --git a/types/node/v4/index.d.ts b/types/node/v4/index.d.ts index 3a7825dff8..db5518575d 100644 --- a/types/node/v4/index.d.ts +++ b/types/node/v4/index.d.ts @@ -1240,7 +1240,7 @@ declare module "child_process" { gid?: number; shell?: boolean | string; } - export function spawn(command: string, args?: string[], options?: SpawnOptions): ChildProcess; + export function spawn(command: string, args?: ReadonlyArray, options?: SpawnOptions): ChildProcess; export interface ExecOptions { cwd?: string; diff --git a/types/node/v6/index.d.ts b/types/node/v6/index.d.ts index e615662fe6..9859d0ba09 100644 --- a/types/node/v6/index.d.ts +++ b/types/node/v6/index.d.ts @@ -1787,7 +1787,7 @@ declare module "child_process" { gid?: number; shell?: boolean | string; } - export function spawn(command: string, args?: string[], options?: SpawnOptions): ChildProcess; + export function spawn(command: string, args?: ReadonlyArray, options?: SpawnOptions): ChildProcess; export interface ExecOptions { cwd?: string; diff --git a/types/node/v7/index.d.ts b/types/node/v7/index.d.ts index 366eb247fd..7d2d34cd8b 100644 --- a/types/node/v7/index.d.ts +++ b/types/node/v7/index.d.ts @@ -1847,7 +1847,7 @@ declare module "child_process" { gid?: number; shell?: boolean | string; } - export function spawn(command: string, args?: string[], options?: SpawnOptions): ChildProcess; + export function spawn(command: string, args?: ReadonlyArray, options?: SpawnOptions): ChildProcess; export interface ExecOptions { cwd?: string; diff --git a/types/node/v8/index.d.ts b/types/node/v8/index.d.ts index 05d617dd58..647d479683 100644 --- a/types/node/v8/index.d.ts +++ b/types/node/v8/index.d.ts @@ -2091,7 +2091,7 @@ declare module "child_process" { windowsHide?: boolean; } - export function spawn(command: string, args?: string[], options?: SpawnOptions): ChildProcess; + export function spawn(command: string, args?: ReadonlyArray, options?: SpawnOptions): ChildProcess; export interface ExecOptions { cwd?: string; diff --git a/types/node/v9/index.d.ts b/types/node/v9/index.d.ts index 5012d70183..d739a5c523 100644 --- a/types/node/v9/index.d.ts +++ b/types/node/v9/index.d.ts @@ -2091,7 +2091,7 @@ declare module "child_process" { windowsHide?: boolean; } - export function spawn(command: string, args?: string[], options?: SpawnOptions): ChildProcess; + export function spawn(command: string, args?: ReadonlyArray, options?: SpawnOptions): ChildProcess; export interface ExecOptions { cwd?: string;