-
Notifications
You must be signed in to change notification settings - Fork 353
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[web3@1.0.0] Generated typings don't have BigNumber as a type #103
Comments
@eswarasai this is expected behavior. Targets like You can always write automatic transformer on userland using a combination of conditional types and dynamically wrapping responses from web3. I know it's not the cleanest solution but this way we can stay out of discussions what API should TypeChain provide in generated wrappers. I think it raises a broader question: should TypeChain allow to customize targets. For example, one can always write own target and just copy web3 target with some changes. I think we should at least document and support easily this use case. |
It seems that web3@1.0.0 actually support Source: |
Note that |
@sebastianst How do you do that? The |
I ended up with some hacks in the "scripts": {
"postinstall": "patch node_modules/truffle-typings/index.d.ts < patches/truffle-typings.d.patch || true",
"build:contracts": "truffle compile",
"build:types": "typechain --target truffle './build/**/*.json'",
"postbuild:types": "sed -i -e 's/BigNumber/BN/g' -e '/bignumber\\.js/d' types/truffle-contracts/index.d.ts",
"build:js": "tsc -p .",
"build": "yarn build:contracts && yarn build:types && yarn build:js",
"test": "truffle test"
} The patch looks like --- /home/self/truffle-typings/index.d.ts 2019-02-04 13:23:01.173368580 +0100
+++ truffle.d.ts 2019-02-04 13:24:30.993372687 +0100
@@ -3,15 +3,19 @@
*/
/// <reference types="chai" />
/// <reference types="mocha" />
+
+declare type BN = import("web3-utils").BN;
+declare type Web3 = import("web3").default;
+
declare const assert: Chai.AssertStatic;
declare const expect: Chai.ExpectStatic;
+declare const web3: Web3;
+
declare function contract(name: string, test: (accounts: Truffle.Accounts) => void): void;
declare const artifacts: Truffle.Artifacts;
-declare const web3: any;
-
/**
* Namespace
*/
@@ -19,10 +23,10 @@
type Accounts = string[];
interface TransactionDetails {
- from: string;
- gas?: number | string;
- gasPrice?: number | string;
- value?: number | string;
+ from?: string;
+ gas?: BN | number | string;
+ gasPrice?: BN | number | string;
+ value?: BN | string;
}
export interface TransactionLog { But I didn't test this for the last three months, so this probably has to be adjusted. Does that answer your question? |
@sebastianst Thanks a lot. This is pretty much the same as we came up with as well. |
@hickscorp @sebastianst I agree that we need "custom" target or something like this. Let me know if you want to work on this |
@krzkaczor I'd be very happy to help but I've literally never worked on a tooling |
@hickscorp don't worry about it, you did a fine job on Some background on this feature. TypeChain under the hood uses https://github.com/krzkaczor/ts-generator which abstracts away some parts regarding type generation. What we could do is allow typechain users to provide custom "plugin" for ts-generator. All existing targets are just plugins for ts-generator. CLI usage could look something like: typechain --target=./typechain-generator.ts --outDir app/contracts './node_modules/neufund-contracts/build/contracts/*.json' |
With
web3@1.0.0
as target, generated types no longer supportBigNumber
for the contracts. As an example, this is the typing generated withweb3@0.26.0
-- https://github.com/MARKETProtocol/types/blob/develop/types/MarketCollateralPool.ts#L178 and the below is generated usingweb3@1.0.0
target which hasstring
instead ofBigNumber
-- https://github.com/MARKETProtocol/types/blob/feature/upgrade-web3-1.0.0/types/MarketCollateralPool.d.ts#L44BigNumber
might need some additional parsing while generating the types I guess. Would be really great if this can be supported soon. Thanks :)The text was updated successfully, but these errors were encountered: