ujjwalguptaofficial / JsStore

Simplifying IndexedDB with SQL like syntax and promises
http://jsstore.net/
MIT License
858 stars 110 forks source link

TypeScript typing is missing some type definitions ) #195

Closed The-MAZZTer closed 3 years ago

The-MAZZTer commented 3 years ago

I am glad to see JSStore has TypeScript support, but I noticed several minor issues that I would like to document here for consideration.

  1. Where objects are not as strongly typed as they could be. In particular I noticed the "or" object seems to be missing. dist/ts/common/types.d.ts line 50 only shows key/value pairs for column names. An entry for or should be added so it shows up in Intellisense in VSCode (and other IDEs).
  2. The transaction callback object in the logic seems to be typed to "any". It should be strongly typed as it is difficult to write transaction code without it (especially since there is a bug in the transaction sample on the site, and no idbstudio example! I will file a separate bug report on this). You can see this on dist/ts/common/types.d.ts line 133. (Also as a side note I think the argument shouldn't be called data since it's not the data you passed in, but the transaction object with the data as one of its properties. Calling it tx or ctx would be more appropriate.)
  3. When I tried to use portions of your typescript without web workers sample on github, in some typescript configurations the import for JsStoreWorker will not work with the error:

error TS7016: Could not find a declaration file for module 'jsstore/dist/jsstore.worker.commonjs2'. '/node_modules/jsstore/dist/jsstore.worker.commonjs2.js' implicitly has an 'any' type. Try npm i --save-dev @types/jsstore if it exists or add a new declaration (.d.ts) file containing declare module 'jsstore/dist/jsstore.worker.commonjs2';

I think it's probably "noImplicitAny" compiler option that does this. This is added by the default Angular project template, and of course developers may wish to add it themselves to enforce strong typing in their code.

This can be resolved by adding the declare module statement specified into a d.ts file. Since the developer is not using the resulting object for anything this is all that needs to be done to fix this.

There's definitely more that can be done to further enhance things, such as use of generics to more tightly enforce typing (see https://github.com/jakearchibald/idb for a good example of this) but I will stop here.

The-MAZZTer commented 3 years ago

I duped this by accident, sorry.