-
Notifications
You must be signed in to change notification settings - Fork 68
Open
Description
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:
[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:
...
declare const Compound: {
(provider?: Provider | string, options?: CompoundOptions): CompoundInstance;
eth: typeof eth;
api: typeof api;
util: typeof util;
_ethers: typeof ethers;
decimals: {
cBAT: number;
cCOMP: number;
cDAI: number;
cETH: number;
cREP: number;
cSAI: number;
cUNI: number;
cUSDC: number;
cUSDT: number;
cWBTC: number;
cZRX: number;
BAT: number;
COMP: number;
DAI: number;
ETH: number;
REP: number;
SAI: number;
UNI: number;
USDC: number;
USDT: number;
WBTC: number;
ZRX: number;
KNC: number;
LINK: number;
BTC: number;
};
comp: {
getCompBalance: typeof comp.getCompBalance;
getCompAccrued: typeof comp.getCompAccrued;
};
};
...
This is because on src/index.ts:93
the constant properties are assigned with Object.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:
...
declare const Compound: {
PriceFeed: string;
Maximillion: string;
CompoundLens: string;
GovernorAlpha: string;
Comptroller: string;
Reservoir: string;
KNC: string;
LINK: string;
BTC: string;
cBAT: string;
cCOMP: string;
cDAI: string;
cETH: string;
cREP: string;
cSAI: string;
cUNI: string;
cUSDC: string;
cUSDT: string;
cWBTC: string;
cZRX: string;
BAT: string;
COMP: string;
DAI: string;
ETH: string;
REP: string;
SAI: string;
UNI: string;
USDC: string;
USDT: string;
WBTC: string;
ZRX: string;
eth: typeof eth;
api: typeof api;
util: typeof util;
_ethers: typeof ethers;
decimals: {
cBAT: number;
cCOMP: number;
cDAI: number;
cETH: number;
cREP: number;
cSAI: number;
cUNI: number;
cUSDC: number;
cUSDT: number;
cWBTC: number;
cZRX: number;
BAT: number;
COMP: number;
DAI: number;
ETH: number;
REP: number;
SAI: number;
UNI: number;
USDC: number;
USDT: number;
WBTC: number;
ZRX: number;
KNC: number;
LINK: number;
BTC: number;
};
comp: {
getCompBalance: typeof comp.getCompBalance;
getCompAccrued: typeof comp.getCompAccrued;
};
};
...
Metadata
Metadata
Assignees
Labels
No labels