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

Typescript error: Property 'forEach' in type 'LRUCache<K, V, FC>' is not assignable to the same property in base type 'Map<K, V>'. #354

Closed
Tracked by #110
paulsmithkc opened this issue Sep 10, 2024 · 7 comments

Comments

@paulsmithkc
Copy link

The following typescript error currently exists in lru-cache@10.4.3 which is causing build errors for users of:

  1. lru-cache@10.4.3
  2. path-scurry@1.11.1
  3. glob@10.4.5
  4. rimraf@5.0.10
node_modules/.pnpm/lru-cache@10.4.3/node_modules/lru-cache/dist/commonjs/index.d.ts:1032:5 - error TS2416: Property 'forEach' in type 'LRUCache<K, V, FC>' is not assignable to the same property in base type 'Map<K, V>'.
  Type '(fn: (v: V, k: K, self: LRUCache<K, V, FC>) => any, thisp?: any) => void' is not assignable to type '(callbackfn: (value: V, key: K, map: Map<K, V>) => void, thisArg?: any) => void'.
    Types of parameters 'fn' and 'callbackfn' are incompatible.
      Types of parameters 'map' and 'self' are incompatible.
        Type 'LRUCache<K, V, FC>' is not assignable to type 'Map<K, V>'.
          The types returned by 'entries().next(...)' are incompatible between these types.
            Type 'IteratorResult<[K, V], void>' is not assignable to type 'IteratorResult<[K, V], undefined>'.
              Type 'IteratorReturnResult<void>' is not assignable to type 'IteratorResult<[K, V], undefined>'.
                Type 'IteratorReturnResult<void>' is not assignable to type 'IteratorReturnResult<undefined>'.
                  Type 'void' is not assignable to type 'undefined'.

1032     forEach(fn: (v: V, k: K, self: LRUCache<K, V, FC>) => any, thisp?: any): void;
@paulsmithkc
Copy link
Author

Upgrading to rimraf@6.0.1 seems to resolve this issue.

@paulsmithkc paulsmithkc changed the title Typscript error: Property 'forEach' in type 'LRUCache<K, V, FC>' is not assignable to the same property in base type 'Map<K, V>'. Typescript error: Property 'forEach' in type 'LRUCache<K, V, FC>' is not assignable to the same property in base type 'Map<K, V>'. Sep 11, 2024
@isaacs
Copy link
Owner

isaacs commented Sep 11, 2024

Upgrade to latest, and set skipLibCheck: true in your tsconfig.

@isaacs isaacs closed this as completed Sep 11, 2024
@marekdedic
Copy link

Hi, I am on rimraf 6.0.1 and I still get this issue.

skipLibCheck is an escape hatch to make things work with incorrect and/or incompatible typings. I'd prefer to fix the typings here instead. Happy to send a PR.

@LoicPoullain
Copy link

This has been fixed for me by downgrading TypeScript v5.6.2 to v5.5.4.

@marekdedic
Copy link

@LoicPoullain I have also noted several new errors with TS 5.6 - do you have any idea if that's a regression or intentional?

@LoicPoullain
Copy link

@marekdedic no idea

@isaacs
Copy link
Owner

isaacs commented Sep 15, 2024

This was fixed on 5ed947d released in lru-cache v11.0.1.

If you are in that version, you don't have this bug. Whatever problem you have is a different problem. Please provide details in a new issue.

If you are not on that version, upgrade. I do not need a pull request, because it is already fixed and shipped.

skipLibCheck: true is recommended by the typescript team officially. It is an "escape hatch" for a mistake in the design of the language.

This issue is resolved, and should not be an issue reported here in the first place. Please stop.

Repository owner locked as resolved and limited conversation to collaborators Sep 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants