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

Types issues in v4 ? #1416

Open
dperetti opened this issue Feb 3, 2025 · 7 comments
Open

Types issues in v4 ? #1416

dperetti opened this issue Feb 3, 2025 · 7 comments

Comments

@dperetti
Copy link

dperetti commented Feb 3, 2025

Describe the bug

Just upgraded my project from v 3.6 to v4. Worked without hassle, but some type definitions seem to be broken in v4.

Versions:

  • Chokidar version 4.02
  • Typescript 5.7.3

To Reproduce:

const watcher = chokidar.watch(watchedPaths, {
        persistent: true,
        useFsEvents: true, // 👈 Typescript Error: useFsEvents does not exist in type
        usePolling: false,
        ignoreInitial: true,
        disableGlobbing: true
      })
      //👇 TS2576: Property on does not exist on type FSWatcher. Did you mean to access the static member FSWatcher. on instead?
      .on('change', (f, stats) => {
              log.info(`File ${f} changed. root: (${sourceFullPath})`)
            })
@dperetti
Copy link
Author

dperetti commented Feb 3, 2025

Ok just figured out it's related to #1392 . But why was it closed?

@43081j
Copy link
Collaborator

43081j commented Feb 3, 2025

as per the last comment in that thread, that person's problem was because we hadn't published the type constraint yet

so unless you also haven't updated to latest 4.x, that issue is unrelated and has correctly been closed

useFsEvents isn't an option anymore, as we don't use fs events. i see there are some remnants of it in the readme, we should remove those.

if removing that doesn't help, let me know. it could be that you need to npm up @types/node but not sure why that'd be the case

@JoshuaHintze
Copy link

JoshuaHintze commented Feb 4, 2025

I'm seeing the same problem.

	"chokidar": "^4.0.3",
	"@types/node": "20.11.20",
	"typescript": "^5.6.3",
               import chokidar, { type FSWatcher } from 'chokidar'; // Tried with and without FSWatcher import

		const watcher: FSWatcher = chokidar.watch(this.inboxPath, {
			persistent: true,
			ignoreInitial: false,
			ignored: (path, stats) => {
				if (stats && stats.isFile()) {
					return !path.endsWith('.json');
				}
				return false;
			}
		});
		
               // ERROR HERE: Property 'on' does not exist on type 'FSWatcher'. Did you mean to access the static member 'FSWatcher.on' instead?ts(2576)

		watcher.on('add', async (filePath) => { console.log('File added: ' + filePath); });

@43081j
Copy link
Collaborator

43081j commented Feb 4, 2025

Which doesn't make much sense since it always had an on method before and after the type changes

Can you tell us exactly which versions it installed? (npm ls @types/node)

And when you mouse over watcher or something in your editor, what is it?

If you jump to the definition of FSWatcher in your editor, what is the first line? (The class declaration)

@JoshuaHintze
Copy link

JoshuaHintze commented Feb 8, 2025

Here are some screen shots.

Image

Image

When I go to definition I get this.

Image

Image

FS Watcher file and first line

Image

Using @types/node 20.11.20

FYI - and maybe this is the culprit. I'm using pnpm and not npm or yarn.

@dperetti
Copy link
Author

dperetti commented Feb 8, 2025

if removing that doesn't help, let me know. it could be that you need to npm up @types/node but not sure why that'd be the case

Thank you, indeed my @types/node was outdated! 🫢

It's now working fine with @types/node 22.10.10 .

@43081j
Copy link
Collaborator

43081j commented Feb 8, 2025

Yep the same for you @JoshuaHintze , the version of @types/node you have is before they added a type parameter to EventEmitter it seems

If you update that, it'll probably work fine

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

No branches or pull requests

3 participants