You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Importing the library into a typescript project and accessing any of the properties defined in src/constants.ts such as Compound.cDAI as in the example in the readme throws the following error:
[tsserver 2339] [E] Property 'cDai' does not exist on type '{ (provider?:
string | Provider, options?: CompoundOptions): CompoundInstance; eth: typeof
Reproducing
On a typescript file with strict mode enabled:
import Compound from "@compound-finance/compound-js";
console.log(Compound.cDai);
Cause
The generated type definition file at 'dist/nodejs/index.d.ts' the constants such as cDAI are missing:
As it can be seen on the proposed fix, the (provider?: Provider | string, options?: CompoundOptions): CompoundInstance; is lost when using the spread operator.
Instead of trying to replicate the behaviour of Object.assign() while preserving types, I added some type definitions for the exported Compound object at src/index.ts, as well as for constants, and decimals at (provider?: Provider | string, options?: CompoundOptions): CompoundInstance;.
Since I was already adding types I also went ahead and wrote interfaces for Account and AccountReponse so that the example at https://compound.finance/docs/compound-js#account can run on strict mode without type issues. Using the new keywoard when initiallizing the compound instance is no longer an issue for the typescript compiler.
Hello,
Importing the library into a typescript project and accessing any of the properties defined in
src/constants.ts
such as Compound.cDAI as in the example in the readme throws the following error:Reproducing
On a typescript file with strict mode enabled:
Cause
The generated type definition file at 'dist/nodejs/index.d.ts' the constants such as cDAI are missing:
This is because on
src/index.ts:93
the constant properties are assigned withObject.assign(Compound, constants);
which does not preserve the types.Proposed fix
Stop using object assign and use the spread operator instead, since types are preserved that way.
Then 'dist/nodejs/index.d.ts' becomes:
The text was updated successfully, but these errors were encountered: