Hello,
I'm struggling to understand why I am getting this error when trying to watch a file for changes.
My code is the following
import * as fs from 'node:fs/promises';
(async () => {
let fileHandle = await fs.open("myFile.txt", "r");
fileHandle.on("change", async () => {
console.log("File changed");
});
const watcher = fs.watch("myFile.txt");
for await (const event of watcher) {
if (event.eventType === "change") {
fileHandle.emit("change");
}
}
})();
The error I am getting is that both, on and emit does not exist on type FileHandle (Property 'on' does not exist on type 'FileHandle'.ts(2339))
However, running the code as JS doesn't give any problem.
I'd appreciate any pointers to help me understand what I am doing wrong.