您将要使用
Promise构造函数:
function writeToFile(filePath: string, arr: string[]): Promise<boolean> { return new Promise((resolve, reject) => { const file = fs.createWriteStream(filePath); for (const row of arr) { file.write(row + "n"); } file.end(); file.on("finish", () => { resolve(true); }); // not sure why you want to pass a boolean file.on("error", reject); // don't forget this! });}


