dethcrypto / truffle-typings

Typescript typings for Truffle
11 stars 9 forks source link

@types/web3 is incompatible with web3's built-in types #14

Open alcuadrado opened 4 years ago

alcuadrado commented 4 years ago

Hey @krzkaczor

I'm having a compilation problem with this package. Here's tsc output:

node_modules/truffle-typings/index.d.ts:8:21 - error TS1340: Module 'web3' does not refer to a type, but is used as a type here. Did you mean 'typeof import('web3')'?

8 declare type Web3 = import("web3");
                      ~~~~~~~~~~~~~~

Found 1 error.

I believe the problem is that this package is based in @types/web3, and not web3's built-int .d.ts files. These typings are incompatible, and the built-in ones "win" over the other, leading to this error.

Do you know how can I fix it? Do you have plans to update this package?

Thanks!

eternauta1337 commented 4 years ago

Hey @krzkaczor I bumped into that error while working with Buidler, and @alcuadrado is actually helping me out.

My current workaround is to comment out lines 8 and 13 in index.d.ts:

// declare type Web3 = import("web3");
// declare const web3: Web3;

Pls let me know if you need more info.

krzkaczor commented 4 years ago

You use @alcuadrado @ajsantander truffle@5 right? Here's basic support: https://github.com/ethereum-ts/TypeChain/pull/199

Tomorrow I will try to wrap it and release (in the worst case as beta).

eternauta1337 commented 4 years ago

Great, thank you!

You use @alcuadrado @ajsantander truffle@5 right?

Yep

krzkaczor commented 4 years ago

@alcuadrado can u prepare a reproduction example for me? I can reproduce it. I just migrated https://github.com/ethereum-ts/truffle-typechain-example/pull/7 and I didnt encounter ANY issues...

krzkaczor commented 4 years ago

Btw. i released truffle v5 target as @typechain/truffle-v5@0.9.0

eternauta1337 commented 4 years ago

@krzkaczor I studied the problem a bit more, while trying to reproduce the issue in a standalone project. I understand it a bit better now.

To reproduce, clone and install: https://github.com/ajsantander/typechain-error-sample

Typechain generates stuff that extends Truffle.ContractInstance from truffle-typings. If you ever want to use the abstract Truffle types like the Truffle.ContractInstance type in your own code, you have to install truffle-typings.

When doing so, 1.0.8 is installed, which produces the following error when attempting to compile typescript:

node_modules/truffle-typings/index.d.ts:8:21 - error TS1340: Module 'web3' does not refer to a type, but is used as a type here. Did you mean 'typeof import('web3')'?

8 declare type Web3 = import("web3");

However, I noticed that Typechain uses version 1.0.4 of truffle-typings, and when pinning to that version, the error is not thrown. As far as I'm concerned, this is a fix for me, but you may want to see a way to avoid this problem for others. There might be breaking changes in truffle-typings that Typechain needs to know about, or something like that.

krzkaczor commented 4 years ago

Thank you! I will investigate it from now but I think you're right about breaking change somewhere in truffle typings. I will release version 1.0.4 as 2.0.0 and backport any useful changes from later as well.

I will let you know when it's done.

forshtat commented 4 years ago

Hi @krzkaczor What is the status of this issue? This is a complete blocker to use the TypeChain project if I understand the problem correctly, isn't it?

krzkaczor commented 4 years ago

@forshtat can u prepare some repro for me? Did you tried using 1.0.4 as noted above? Also, you can use patch-package to fix your typechain locally if you don't want to wait for upstream fixes.