Type spawn's args as a ReadonlyArray of string (#25487)

At the moment, this snippet:

```ts
const spawnArgs: ReadonlyArray<string> = ['foo', 'bar'];
spawn('foobar', spawnArgs);
```

fails with:

```
Argument of type 'ReadonlyArray<string>' is not assignable to parameter of type 'string[] | undefined'.
  Type 'ReadonlyArray<string>' 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.
This commit is contained in:
Jérémie Astori
2018-05-03 08:57:27 -07:00
committed by Andy
parent f2236bdec5
commit dd0d4ad0c4
7 changed files with 7 additions and 7 deletions
+1 -1
View File
@@ -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<string>, options?: SpawnOptions): ChildProcess;
export interface ExecOptions {
cwd?: string;
+1 -1
View File
@@ -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<string>, options?: {
cwd?: string;
stdio?: any;
custom?: any;
+1 -1
View File
@@ -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<string>, options?: SpawnOptions): ChildProcess;
export interface ExecOptions {
cwd?: string;
+1 -1
View File
@@ -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<string>, options?: SpawnOptions): ChildProcess;
export interface ExecOptions {
cwd?: string;
+1 -1
View File
@@ -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<string>, options?: SpawnOptions): ChildProcess;
export interface ExecOptions {
cwd?: string;
+1 -1
View File
@@ -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<string>, options?: SpawnOptions): ChildProcess;
export interface ExecOptions {
cwd?: string;
+1 -1
View File
@@ -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<string>, options?: SpawnOptions): ChildProcess;
export interface ExecOptions {
cwd?: string;