paulmillr / chokidar

Minimal and efficient cross-platform file watching library
https://paulmillr.com
MIT License
10.8k stars 574 forks source link

Incompatibility of types with recent changes in `@types/node` #1299

Closed devversion closed 7 months ago

devversion commented 7 months ago

Versions (please complete the following information):

To Reproduce:

  1. Update @types/node in this repository to e.g. latest Node v16 types: 16.18.75
  2. Notice that types/index.d.ts is not properly extending fs.FSWatcher
  incorrectly implements interface 'import("fs").FSWatcher'.
  Type 'FSWatcher' is missing the following properties from type 'FSWatcher': ref, unref

Expected behavior Chokidar types should work with most recent versions of @types/node. TypeScript projects will face similar errors when building with skipLibCheck: false (which is the default)

Additional context

Change in @types/node that made this breaking change (to match Node versions) in a SemVer patch: https://github.com/DefinitelyTyped/DefinitelyTyped/pull/68300

Semigradsky commented 7 months ago

There is a possible quick fix - change this line https://github.com/paulmillr/chokidar/blob/5589454f3e082c5c476de11277346ee3debe5ad4/types/index.d.ts#L9 to

export class FSWatcher extends EventEmitter implements Omit<fs.FSWatcher, 'ref' | 'unref'> { 

Or define these missed methods.

paulmillr commented 7 months ago

so why was it fine before? maybe it’s not ours issue?

devversion commented 7 months ago

I don't have enough context unfortunately, but at first glance it looks like:

Semigradsky commented 7 months ago

ref and unref were added in v14.3.0, v12.20.0 to Node.js but were missed in @types/node.

trollspank commented 7 months ago

For those that may come here later... when working with Capacitor their @capacitor-community/electron module (which sets up electron for Capacitor) the 'npm run build' will fail for capacitor as it uses chokidar in setup.ts.

You have been warned :) Work around until this is resolved is 'npm install @types/node@16.18.71' within your electron directory.

uiolee commented 7 months ago

same issue when working with @types/node@18.19.9 and newer

Cellule commented 7 months ago

I wasn't successful with the Omit<fs.FSWatcher, "ref" | "unref"> solution has methods returning this would not be compatible anymore.

Instead for now I'm going with this solution. Something looks off so I'm not sure enough to make a PR on this repo, but at least it unblocks me

export class FSWatcher extends EventEmitter implements fs.FSWatcher {
  ref(): never;
  unref(): never;
}
paulmillr commented 7 months ago

published 3.6.0