isaacs / node-lru-cache

A fast cache that automatically deletes the least recently used items
http://isaacs.github.io/node-lru-cache/
ISC License
5.35k stars 353 forks source link

TS 5.6.0-beta compilation error in a project consuming lru-cache #348

Closed jeremymeng closed 3 months ago

jeremymeng commented 3 months ago

typescript 5.5.4 works fine, but 5.6.0-beta gives the following error. Repro project: https://github.com/jeremymeng/lru-cache-ts-5.6.0-beta. .

node_modules/lru-cache/dist/commonjs/index.d.ts:973:5 - error TS2416: Property 'entries' in type 'LRUCache<K, V, FC>' is not assignable to the same property in base type 'Map<K, V>'.
  Type '() => Generator<[K, V], void, unknown>' is not assignable to type '() => BuiltinIterator<[K, V], undefined, any>'.
    Call signature return types 'Generator<[K, V], void, unknown>' and 'BuiltinIterator<[K, V], undefined, any>' are incompatible.
      The types returned by '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'.

973     entries(): Generator<[K, V], void, unknown>;
        ~~~~~~~

node_modules/lru-cache/dist/commonjs/index.d.ts:985:5 - error TS2416: Property 'keys' in type 'LRUCache<K, V, FC>' is not assignable to the same property in base type 'Map<K, V>'.
  Type '() => Generator<K, void, unknown>' is not assignable to type '() => BuiltinIterator<K, undefined, any>'.
    Call signature return types 'Generator<K, void, unknown>' and 'BuiltinIterator<K, undefined, any>' are incompatible.
      The types returned by 'next(...)' are incompatible between these types.
        Type 'IteratorResult<K, void>' is not assignable to type 'IteratorResult<K, undefined>'.
          Type 'IteratorReturnResult<void>' is not assignable to type 'IteratorResult<K, undefined>'.
            Type 'IteratorReturnResult<void>' is not assignable to type 'IteratorReturnResult<undefined>'.
              Type 'void' is not assignable to type 'undefined'.

985     keys(): Generator<K, void, unknown>;
        ~~~~

node_modules/lru-cache/dist/commonjs/index.d.ts:997:5 - error TS2416: Property 'values' in type 'LRUCache<K, V, FC>' is not assignable to the same property in base type 'Map<K, V>'.
  Type '() => Generator<V, void, unknown>' is not assignable to type '() => BuiltinIterator<V, undefined, any>'.
    Call signature return types 'Generator<V, void, unknown>' and 'BuiltinIterator<V, undefined, any>' are incompatible.
      The types returned by 'next(...)' are incompatible between these types.
        Type 'IteratorResult<V, void>' is not assignable to type 'IteratorResult<V, undefined>'.
          Type 'IteratorReturnResult<void>' is not assignable to type 'IteratorResult<V, undefined>'.
            Type 'IteratorReturnResult<void>' is not assignable to type 'IteratorReturnResult<undefined>'.
              Type 'void' is not assignable to type 'undefined'.

997     values(): Generator<V, void, unknown>;
        ~~~~~~

node_modules/lru-cache/dist/commonjs/index.d.ts:1009:5 - error TS2416: Property '[Symbol.iterator]' in type 'LRUCache<K, V, FC>' is not assignable to the same property in base type 'Map<K, V>'.
  Type '() => Generator<[K, V], void, unknown>' is not assignable to type '() => BuiltinIterator<[K, V], undefined, any>'.
    Call signature return types 'Generator<[K, V], void, unknown>' and 'BuiltinIterator<[K, V], undefined, any>' are incompatible.
      The types returned by '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'.

1009     [Symbol.iterator](): Generator<[K, V], void, unknown>;
         ~~~~~~~~~~~~~~~~~

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;
         ~~~~~~~

Found 5 errors in the same file, starting at: node_modules/lru-cache/dist/commonjs/index.d.ts:973
isaacs commented 3 months ago

This project builds fine, as you say. Use skipLibCheck: true and don't worry about what your libs are doing. It's fine.

mrginglymus commented 2 months ago

A ~more~ differently focussed workaround, until lru-cache supports 5.6, is to disable the new strictBuiltinIteratorReturn option introduced in https://github.com/microsoft/TypeScript/pull/58243