Skip to content

fix: update VFSStatWatcher typings#32

Open
mrazauskas wants to merge 1 commit into
platformatic:mainfrom
mrazauskas:update-VFSStatWatcher-typings
Open

fix: update VFSStatWatcher typings#32
mrazauskas wants to merge 1 commit into
platformatic:mainfrom
mrazauskas:update-VFSStatWatcher-typings

Conversation

@mrazauskas
Copy link
Copy Markdown

@mrazauskas mrazauskas commented May 28, 2026

This PR updates typings of the VFSStatWatcher class.

The problem is that addListener() and removeListener() are trying to override type declarations of EventEmitter with different implementations. For instance, addListener() declares one argument and a void return type, but the original declaration has two arguments and a this return type. TypeScript rejects the new declaration as incompatible, see microsoft/TypeScript#6094.

This problem is reported in #31. The newer version of TSTyche added checks for .d.ts files. The change should unblock the PR.

The types are correct and based on the current implementation:

vfs/lib/watcher.js

Lines 246 to 256 in 2882dd2

addListener(listener) {
this.#listeners.add(listener);
this.on('change', listener);
}
removeListener(listener) {
const had = this.#listeners.has(listener);
this.#listeners.delete(listener);
super.removeListener('change', listener);
return had;
}

Solutions

The typings are correct. So I think using @ts-expect-error is ok solution.

Another good solution can be found in #33.

Alternatively, it is possible to disable the additional TSTyche checks. But users with "skipLibCheck": false set will see the error.

The error can be silenced by adding the original type declarations of addListener() and removeListener() as function overloads. But the typings would be incorrect, because methods of VFSStatWatcher do not take two arguments.


Close #33

Signed-off-by: mrazauskas <tom@mrazauskas.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant