aleph.js icon indicating copy to clipboard operation
aleph.js copied to clipboard

build error in module: this is defined/typed as an arg is not skipped

Open elverskog opened this issue 3 years ago • 1 comments
trafficstars

I get a browser error (pasted at bottom) when running aleph as deno task dev, when using pouchdb_deno.

running deno task build, with that module in place, is a whole different topic (panic about threadpooling).

Anyways...In pouch (a few modules really) there's a callback that is supposed to be passed down a chain. It becomes undefined early in the chain, eventually causing an error. The callback gets lost because the function idb below is run via call and in Aleph this becomes the first argument, causing opts to equal the callback.

  function idb(
    this: any,
    opts: PouchDB.IdbAdapter.IdbAdapterConfiguration,
    callback: any,
  ) {

If I make a local copy of the module and remove this: any in that file, the error(s) go away.

However, my understanding, from speaking to the author of pouchdb_deno ( @aaronhuggins ) is that the TypeScript compiler and the Deno bundler both strip this keyword out (if it is in the first position) but that the Aleph bundler does not.

Is this something that should be adjusted?

The error(s): Uncaught TypeError: fun is not a function tryCode pouchdb-adapter-idb.js:786 runCallback pouchdb-adapter-idb.js:801 completeSetup pouchdb-adapter-idb.js:1511 oncomplete pouchdb-adapter-idb.js:1543 onsuccess pouchdb-adapter-idb.js:1541 init pouchdb-adapter-idb.js:1476 IdbPouch pouchdb-adapter-idb.js:969 runAction pouchdb-adapter-idb.js:800 applyNext pouchdb-adapter-idb.js:796 enqueueTask pouchdb-adapter-idb.js:808 IdbPouch pouchdb-adapter-idb.js:968 idb mod.ts:41 PouchDB pouchdb-core.js:1401

elverskog avatar Jun 24 '22 21:06 elverskog

Relevant TypeScript compiler doc for using this parameter definition.

https://www.typescriptlang.org/docs/handbook/2/functions.html#declaring-this-in-a-function

aaronhuggins avatar Jun 26 '22 23:06 aaronhuggins