この単純なモジュールは、ChildProcess
のインスタンスを返す関数をエクスポートします。問題は、ChildProcess
クラスへの参照を取得する方法がわからないため、戻り値の型情報を追加する方法がわかりません。TypeScript型のChildProcessクラスへの参照
//core
import * as cp from 'child_process';
import * as path from 'path';
//project
const run = path.resolve(__dirname +'/lib/run.sh');
export = function($commands: Array<string>, args?: Array<string>) {
const commands = $commands.map(function(c){
return String(c).trim();
});
return cp.spawn(run, (args || []), {
env: Object.assign({}, process.env, {
GENERIC_SUBSHELL_COMMANDS: commands.join('\n')
})
});
};
Node.jsのドキュメントを見ると、cp.spawn()はChildProcessクラスのインスタンスを返します。
あなたがここを見ている場合: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/node/index.d.ts
を私たちは子プロセスクラスの型定義を参照してください。 https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/node/index.d.ts#L1599
しかし、私は私の活字体のコードでこれを参照する方法を混乱しています。
私は@types/node
をインポートするとは思われませんが、これはdevDependencyであるはずです。
私は何をすべきですか?
のように、私は何かをする必要があり:私にとって
import * as cp from 'child_process';
export = function($commands: Array<string>, args?: Array<string>): cp.ChildProcess {
//...
}
が、これがどのように動作するか本当にわからない、まだ、それを得たが、それはそれを行う必要があり、私は確認してみましょう –