Support of TS 4.1 with noUncheckedIndexedAccess
Closed this issue · 1 comments
ondrejvelisek commented
Hi there,
I have similar problem as #37
TS 4.1 introduced new compilerOption noUncheckedIndexedAccess. see:
https://www.typescriptlang.org/tsconfig#noUncheckedIndexedAccess
When I use TS 4.1 or above with this option, micro-memoize fails to compile.
To reproduce bug, create a project with TS 4.1 or above, turn on noUncheckedIndexedAccess, import and use micro-memoize and run a TS build. I see:
tsc --noEmit
node_modules/micro-memoize/src/Cache.ts:82:23 - error TS2345: Argument of type 'Key | undefined' is not assignable to parameter of type 'Key'.
Type 'undefined' is not assignable to type 'any[]'.
82 if (isMatchingKey(keys[0], keyToMatch)) {
~~~~~~~
node_modules/micro-memoize/src/Cache.ts:88:27 - error TS2345: Argument of type 'Key | undefined' is not assignable to parameter of type 'Key'.
Type 'undefined' is not assignable to type 'any[]'.
88 if (isMatchingKey(keys[index], keyToMatch)) {
~~~~~~~~~~~
node_modules/micro-memoize/src/Cache.ts:176:13 - error TS2339: Property 'length' does not exist on type 'Key | undefined'.
176 const { length } = existingKey;
~~~~~~
node_modules/micro-memoize/src/Cache.ts:186:22 - error TS2532: Object is possibly 'undefined'.
186 if (!isEqual(existingKey[index], keyToMatch[index])) {
~~~~~~~~~~~
node_modules/micro-memoize/src/Cache.ts:194:20 - error TS2532: Object is possibly 'undefined'.
194 return isEqual(existingKey[0], keyToMatch[0]) ? 0 : -1;
~~~~~~~~~~~
node_modules/micro-memoize/src/Cache.ts:220:7 - error TS2322: Type 'Key | undefined' is not assignable to type 'Key'.
Type 'undefined' is not assignable to type 'any[]'.
220 keys[index + 1] = keys[index];
~~~~~~~~~~~~~~~
node_modules/micro-memoize/src/Cache.ts:269:43 - error TS2345: Argument of type 'Key | undefined' is not assignable to parameter of type 'RawKey'.
Type 'undefined' is not assignable to type 'RawKey'.
269 const keyIndex = this.getKeyIndex(firstKey);
~~~~~~~~
Found 7 errors in the same file, starting at: node_modules/micro-memoize/src/Cache.ts:82
planttheidea commented
This should be fixed as-of 4.0.10
. If you have any more issues, please let me know!