I am glad to see JSStore has TypeScript support, but I noticed several minor issues that I would like to document here for consideration.
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).
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.)
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.
I am glad to see JSStore has TypeScript support, but I noticed several minor issues that I would like to document here for consideration.
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).dist/ts/common/types.d.ts line 133
. (Also as a side note I think the argument shouldn't be calleddata
since it's not the data you passed in, but the transaction object with the data as one of its properties. Calling ittx
orctx
would be more appropriate.)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 containingdeclare 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 ad.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.