Skip to content
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

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

Open
alcuadrado opened this issue Jan 20, 2020 · 9 comments
Open

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

alcuadrado opened this issue Jan 20, 2020 · 9 comments

Comments

@alcuadrado
Copy link

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
Copy link

eternauta1337 commented Jan 20, 2020

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
Copy link
Member

You use @alcuadrado @ajsantander truffle@5 right? Here's basic support: dethcrypto/TypeChain#199

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

@eternauta1337
Copy link

eternauta1337 commented Jan 21, 2020

Great, thank you!

You use @alcuadrado @ajsantander truffle@5 right?

Yep

@krzkaczor
Copy link
Member

@alcuadrado can u prepare a reproduction example for me? I can reproduce it. I just migrated dethcrypto/truffle-typechain-example#7 and I didnt encounter ANY issues...

@krzkaczor
Copy link
Member

Btw. i released truffle v5 target as @typechain/[email protected]

@eternauta1337
Copy link

eternauta1337 commented Jan 22, 2020

@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
Copy link
Member

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.

gorgos added a commit to laminar-protocol/flow-protocol-ethereum that referenced this issue Mar 10, 2020
* older truffle-typings required, see dethcrypto/truffle-typings#14 (comment)
@forshtat
Copy link

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
Copy link
Member

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants