#EventEmitter

1 messages · Page 1 of 1 (latest)

ocean niche
#

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.

dapper sundial
#
  • do you have @types/node installed?
  • have you tried running tsc from the command line?
  • have you tried restarting the ts server?
#

oh, it seems like that's a gap in @types/node?

nimble galeBOT
#
// TODO: Add `EventEmitter` close
interface FileHandle {
ocean niche
#

OK, thank you. I understand now

#

!resolved

dapper sundial
#

there's like zero discussion regarding this wtf