@@ -80,6 +80,7 @@ declare var SlowBuffer: {
80
80
81
81
82
82
// Buffer class
83
+ type BufferEncoding = "ascii" | "utf8" | "utf16le" | "ucs2" | "binary" | "hex" ;
83
84
interface Buffer extends NodeBuffer { }
84
85
85
86
/**
@@ -967,30 +968,50 @@ declare module "child_process" {
967
968
export interface ExecOptions {
968
969
cwd ?: string ;
969
970
env ?: any ;
970
- encoding ?: string ;
971
971
shell ?: string ;
972
972
timeout ?: number ;
973
973
maxBuffer ?: number ;
974
974
killSignal ?: string ;
975
975
uid ?: number ;
976
976
gid ?: number ;
977
977
}
978
- export function exec ( command : string , options : ExecOptions , callback ?: ( error : Error , stdout : Buffer , stderr : Buffer ) => void ) : ChildProcess ;
979
- export function exec ( command : string , callback ?: ( error : Error , stdout : Buffer , stderr : Buffer ) => void ) : ChildProcess ;
978
+ export interface ExecOptionsWithStringEncoding extends ExecOptions {
979
+ encoding : BufferEncoding ;
980
+ }
981
+ export interface ExecOptionsWithBufferEncoding extends ExecOptions {
982
+ encoding : string ; // specify `null`.
983
+ }
984
+ export function exec ( command : string , callback ?: ( error : Error , stdout : string , stderr : string ) => void ) : ChildProcess ;
985
+ export function exec ( command : string , options : ExecOptionsWithStringEncoding , callback ?: ( error : Error , stdout : string , stderr : string ) => void ) : ChildProcess ;
986
+ // usage. child_process.exec("tsc", {encoding: null as string}, (err, stdout, stderr) => {});
987
+ export function exec ( command : string , options : ExecOptionsWithBufferEncoding , callback ?: ( error : Error , stdout : Buffer , stderr : Buffer ) => void ) : ChildProcess ;
988
+ export function exec ( command : string , options : ExecOptions , callback ?: ( error : Error , stdout : string , stderr : string ) => void ) : ChildProcess ;
980
989
981
990
export interface ExecFileOptions {
982
991
cwd ?: string ;
983
992
env ?: any ;
984
- encoding ?: string ;
985
993
timeout ?: number ;
986
994
maxBuffer ?: number ;
987
995
killSignal ?: string ;
988
996
uid ?: number ;
989
997
gid ?: number ;
990
998
}
991
- export function execFile ( file : string , callback ?: ( error : Error , stdout : Buffer , stderr : Buffer ) => void ) : ChildProcess ;
992
- export function execFile ( file : string , args ?: string [ ] , callback ?: ( error : Error , stdout : Buffer , stderr : Buffer ) => void ) : ChildProcess ;
993
- export function execFile ( file : string , args ?: string [ ] , options ?: ExecFileOptions , callback ?: ( error : Error , stdout : Buffer , stderr : Buffer ) => void ) : ChildProcess ;
999
+ export interface ExecFileOptionsWithStringEncoding extends ExecFileOptions {
1000
+ encoding : BufferEncoding ;
1001
+ }
1002
+ export interface ExecFileOptionsWithBufferEncoding extends ExecFileOptions {
1003
+ encoding : string ; // specify `null`.
1004
+ }
1005
+ export function execFile ( file : string , callback ?: ( error : Error , stdout : string , stderr : string ) => void ) : ChildProcess ;
1006
+ export function execFile ( file : string , options ?: ExecFileOptionsWithStringEncoding , callback ?: ( error : Error , stdout : string , stderr : string ) => void ) : ChildProcess ;
1007
+ // usage. child_process.execFile("file.sh", {encoding: null as string}, (err, stdout, stderr) => {});
1008
+ export function execFile ( file : string , options ?: ExecFileOptionsWithBufferEncoding , callback ?: ( error : Error , stdout : Buffer , stderr : Buffer ) => void ) : ChildProcess ;
1009
+ export function execFile ( file : string , options ?: ExecFileOptions , callback ?: ( error : Error , stdout : string , stderr : string ) => void ) : ChildProcess ;
1010
+ export function execFile ( file : string , args ?: string [ ] , callback ?: ( error : Error , stdout : string , stderr : string ) => void ) : ChildProcess ;
1011
+ export function execFile ( file : string , args ?: string [ ] , options ?: ExecFileOptionsWithStringEncoding , callback ?: ( error : Error , stdout : string , stderr : string ) => void ) : ChildProcess ;
1012
+ // usage. child_process.execFile("file.sh", ["foo"], {encoding: null as string}, (err, stdout, stderr) => {});
1013
+ export function execFile ( file : string , args ?: string [ ] , options ?: ExecFileOptionsWithBufferEncoding , callback ?: ( error : Error , stdout : Buffer , stderr : Buffer ) => void ) : ChildProcess ;
1014
+ export function execFile ( file : string , args ?: string [ ] , options ?: ExecFileOptions , callback ?: ( error : Error , stdout : string , stderr : string ) => void ) : ChildProcess ;
994
1015
995
1016
export interface ForkOptions {
996
1017
cwd ?: string ;
@@ -1016,15 +1037,28 @@ declare module "child_process" {
1016
1037
encoding ?: string ;
1017
1038
shell ?: boolean | string ;
1018
1039
}
1019
- export function spawnSync ( command : string , args ?: string [ ] , options ?: SpawnSyncOptions ) : {
1040
+ export interface SpawnSyncOptionsWithStringEncoding extends SpawnSyncOptions {
1041
+ encoding : BufferEncoding ;
1042
+ }
1043
+ export interface SpawnSyncOptionsWithBufferEncoding extends SpawnSyncOptions {
1044
+ encoding : string ; // specify `null`.
1045
+ }
1046
+ export interface SpawnSyncReturns < T > {
1020
1047
pid : number ;
1021
1048
output : string [ ] ;
1022
- stdout : string | Buffer ;
1023
- stderr : string | Buffer ;
1049
+ stdout : T ;
1050
+ stderr : T ;
1024
1051
status : number ;
1025
1052
signal : string ;
1026
1053
error : Error ;
1027
- } ;
1054
+ }
1055
+ export function spawnSync ( command : string ) : SpawnSyncReturns < Buffer > ;
1056
+ export function spawnSync ( command : string , options ?: SpawnSyncOptionsWithStringEncoding ) : SpawnSyncReturns < string > ;
1057
+ export function spawnSync ( command : string , options ?: SpawnSyncOptionsWithBufferEncoding ) : SpawnSyncReturns < Buffer > ;
1058
+ export function spawnSync ( command : string , options ?: SpawnSyncOptions ) : SpawnSyncReturns < Buffer > ;
1059
+ export function spawnSync ( command : string , args ?: string [ ] , options ?: SpawnSyncOptionsWithStringEncoding ) : SpawnSyncReturns < string > ;
1060
+ export function spawnSync ( command : string , args ?: string [ ] , options ?: SpawnSyncOptionsWithBufferEncoding ) : SpawnSyncReturns < Buffer > ;
1061
+ export function spawnSync ( command : string , args ?: string [ ] , options ?: SpawnSyncOptions ) : SpawnSyncReturns < Buffer > ;
1028
1062
1029
1063
export interface ExecSyncOptions {
1030
1064
cwd ?: string ;
@@ -1039,7 +1073,16 @@ declare module "child_process" {
1039
1073
maxBuffer ?: number ;
1040
1074
encoding ?: string ;
1041
1075
}
1042
- export function execSync ( command : string , options ?: ExecSyncOptions ) : string | Buffer ;
1076
+ export interface ExecSyncOptionsWithStringEncoding extends ExecSyncOptions {
1077
+ encoding : BufferEncoding ;
1078
+ }
1079
+ export interface ExecSyncOptionsWithBufferEncoding extends ExecSyncOptions {
1080
+ encoding : string ; // specify `null`.
1081
+ }
1082
+ export function execSync ( command : string ) : Buffer ;
1083
+ export function execSync ( command : string , options ?: ExecSyncOptionsWithStringEncoding ) : string ;
1084
+ export function execSync ( command : string , options ?: ExecSyncOptionsWithBufferEncoding ) : Buffer ;
1085
+ export function execSync ( command : string , options ?: ExecSyncOptions ) : Buffer ;
1043
1086
1044
1087
export interface ExecFileSyncOptions {
1045
1088
cwd ?: string ;
@@ -1053,7 +1096,19 @@ declare module "child_process" {
1053
1096
maxBuffer ?: number ;
1054
1097
encoding ?: string ;
1055
1098
}
1056
- export function execFileSync ( command : string , args ?: string [ ] , options ?: ExecFileSyncOptions ) : string | Buffer ;
1099
+ export interface ExecFileSyncOptionsWithStringEncoding extends ExecFileSyncOptions {
1100
+ encoding : BufferEncoding ;
1101
+ }
1102
+ export interface ExecFileSyncOptionsWithBufferEncoding extends ExecFileSyncOptions {
1103
+ encoding : string ; // specify `null`.
1104
+ }
1105
+ export function execFileSync ( command : string ) : Buffer ;
1106
+ export function execFileSync ( command : string , options ?: ExecFileSyncOptionsWithStringEncoding ) : string ;
1107
+ export function execFileSync ( command : string , options ?: ExecFileSyncOptionsWithBufferEncoding ) : Buffer ;
1108
+ export function execFileSync ( command : string , options ?: ExecFileSyncOptions ) : Buffer ;
1109
+ export function execFileSync ( command : string , args ?: string [ ] , options ?: ExecFileSyncOptionsWithStringEncoding ) : string ;
1110
+ export function execFileSync ( command : string , args ?: string [ ] , options ?: ExecFileSyncOptionsWithBufferEncoding ) : Buffer ;
1111
+ export function execFileSync ( command : string , args ?: string [ ] , options ?: ExecFileSyncOptions ) : Buffer ;
1057
1112
}
1058
1113
1059
1114
declare module "url" {
0 commit comments