Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed

Comments

@devversion
Copy link

devversion commented Jan 24, 2024

Versions (please complete the following information):

  • Chokidar version [e.g. 3.2.1 or commit hash] 3.5.3
  • Node version [e.g. 12.11.0, ensure you are using the latest node.js] 18.17.1
  • OS version: [e.g. Ubuntu 19.04 or MacOS 10.15 or Windows 10] Ubuntu

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: DefinitelyTyped/DefinitelyTyped#68300

@Semigradsky
Copy link

There is a possible quick fix - change this line

export class FSWatcher extends EventEmitter implements fs.FSWatcher {

to

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

Or define these missed methods.

@paulmillr
Copy link
Owner

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

@devversion
Copy link
Author

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

  • fs.FSWatcher actually defines these two methods always
    • They are now typed in @types/node, and users will see those.
    • Chokidar may be validated against this version of the Node types.
  • The watcher type from chokidar "implements" fs.FSWatcher but with the new interface, it does not fully implement the latest version of fs.FSWatcher.
    • This is likely fine, but the type just needs to be updated to implement a "subset" of Node's FSWatcher.

@Semigradsky
Copy link

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

@trollspank
Copy link

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
Copy link

uiolee commented Jan 26, 2024

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

@Cellule
Copy link

Cellule commented Jan 30, 2024

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
Copy link
Owner

published 3.6.0

colinrotherham added a commit to alphagov/govuk-frontend that referenced this issue Feb 9, 2024
colinrotherham added a commit to alphagov/govuk-design-system that referenced this issue Feb 9, 2024
colinrotherham added a commit to alphagov/govuk-design-system that referenced this issue Feb 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment