morrys / wora

Write Once, Render Anywhere. typescript libraries: cache-persist, apollo-offline, relay-offline, offline-first, apollo-cache, relay-store, netinfo, detect-network
https://morrys.github.io/wora/docs/introduction
MIT License
174 stars 4 forks source link

relay-store: Enabling TSLint strict flag results in type errors #120

Closed olerichter00 closed 2 years ago

olerichter00 commented 2 years ago

Hi @morrys ! 👋

Firstly, thanks for your amazing work! 🙂

We are using @wora/relay-store 6.0.0 in our project Eigen and ran into a type issue with strict mode enabled.

I've create a PR to fix the type issues we encountered and here is the diff that solved my problem (from patch-package):

TSConfig Error Message:

node_modules/@wora/relay-store/lib/RecordSource.d.ts:22:5 - error TS2416: Property 'toJSON' in type 'RecordSource' is not assignable to the same property in base type 'IMutableRecordSourceOffline'.
  Type '() => RecordMap' is not assignable to type '() => { [key: string]: Record<{}>; }'.
    Type 'RecordMap' is not assignable to type '{ [key: string]: Record<{}>; }'.
      'string' index signatures are incompatible.
        Type 'Record<{}> | null | undefined' is not assignable to type 'Record<{}>'.
          Type 'undefined' is not assignable to type 'Record<{}>'.

22     toJSON(): RecordMap;
       ~~~~~~
```diff
diff --git a/node_modules/@wora/relay-store/lib/RecordSource.d.ts b/node_modules/@wora/relay-store/lib/RecordSource.d.ts
index 422b7bf..74cfe72 100644
--- a/node_modules/@wora/relay-store/lib/RecordSource.d.ts
+++ b/node_modules/@wora/relay-store/lib/RecordSource.d.ts
@@ -1,5 +1,5 @@
 import { RecordState } from 'relay-runtime';
-import { MutableRecordSource, Record, RecordMap } from 'relay-runtime/lib/store/RelayStoreTypes';
+import { MutableRecordSource, Record } from 'relay-runtime/lib/store/RelayStoreTypes';
 import { DataCache, CacheOptions } from '@wora/cache-persist';
 export interface IMutableRecordSourceOffline extends MutableRecordSource {
     restore(): Promise<DataCache>;
@@ -19,6 +19,6 @@ export declare class RecordSource implements IMutableRecordSourceOffline {
     remove(dataID: string): void;
     set(dataID: string, record: Record): void;
     size(): number;
-    toJSON(): RecordMap;
+    toJSON(): { [key: string]: Record };
 }
 //# sourceMappingURL=RecordSource.d.ts.map

This issue body was partially generated by patch-package.

morrys commented 2 years ago

fixed in https://github.com/morrys/wora/releases/tag/relay-store%406.0.1

thanks again for the PR and the issue 👍