`fake-timers` 7.1.x compile error "Cannot find name 'queueMicrotask'."

1.4k views Asked by At

I'm trying to compile a Salesforce sfdx plugin which is a node project with (among others) the following dependency chain that ultimately leads to fake-timers@^7.1.0:

@salesforce/[email protected] -> @oclif/test@^1.2.4 -> fancy-test@^1.4.3 -> @types/sinon@* -> @sinonjs/fake-timers@^7.1.0.

When compiling it with the Typescript compiler tsc, I get the following error:

node_modules/@sinonjs/fake-timers/types/fake-timers-src.d.ts:11:28 - error TS2304: Cannot find name 'queueMicrotask'.

11     queueMicrotask: typeof queueMicrotask;
                              ~~~~~~~~~~~~~~


Found 1 error.

error Command failed with exit code 1.

This looks like a bug in fake-timers-src.d.ts but introduced in 7.1.0 so I could try to lock the version at 7.0.5 but that might break all kinds of other things.

Does anybody who uses/maintains fake-timers know how to fix this? Or will this be fixed in a future version?

BTW I'm a total NodeJS n00b so if there's something really obvious here that I'm missing, please be kind and just tell me what it is :)

Thanks! Frans

1

There are 1 answers

1
oligofren On

Frans! fatso83 from the Sinon team here :)

The problem here has all to do with TypeScript and nothing to do with Node, so I feel your pain. No wonder you are wondering. The problem is that the definitions are probably missing that property. For version 7 we tried to generate TypeScript definitions from JSDoc. This works reasonably well for simpler type, but ultimately, TypeScript is more powerful in describing types than JSDoc (like the typeof operator), so it was an uphill battle that would never result in the same quality as the types available from the external Definitely Typed project. We ended up abandoning that effort and therefore this will not be fixed, but it will naturally go away with version 8 (that will not be shipping its own types).

What you can do is this: npm install @sinonjs/fake-timers@6 (which is the previous version) and npm install @types/sinonjs__fake-timers@6 (which are the externally maintained types).

You might find some background for this in this issue.