Web3.js: Typescript rewrite

Created on 17 Jan 2018  路  11Comments  路  Source: ChainSafe/web3.js

Hi,

Now that the library is being split into smaller modules, are there any plans to use Typescript as the primary language? I won't list all the pros/cons as most of us already know what's at stake, I'd just point out that the current definition file is very often out-of-sync and it would help fixing this issue 馃檪.

I'd gladly volunteer to start converting code (starting with web3-utils) but I'd like to know what's your stance on it.

Thank you in advance!

2.x Stale discussion enhancement

Most helpful comment

The library should be rewritten to Typescript for the following reasons:

  • Type safety! Dealing with smart contracts, making sure types are correct is a must!
  • Write code once in Typescript, then have it generate targets for ES3, ES5, ES6, ES7 ... Only one codebase!
  • Typings will be automatically generated and accurate. Always.

All 11 comments

You mean converting the whole lib to typescript?
Whats the benefit for smaller libs?
I dont know typescript myself. Could you list the pros and cons (besides that its typed)

In my experience, it makes it easier for external contributors to dive into the code (types bring accurate auto-completion and it feels "safe" to commit code that compiles).

The (only?) downside is that it adds a compilation step and requires developers (and especially active members such as you) to learn Typescript (considering the current complexity of the library it should be a joy ride).

Since 1.0 is split into relatively small packages, I think it makes it even easier to slowly migrate the codebase. We can start with web3-utils and rollback to plain-ol' JS if there is an issue.

I know this would be a big change, we can definitely wait for more feedback from other contributors to make sure it's the right decision 馃檪. Plus I won't be available for 2 weeks starting Monday 馃槢

Hi,

we have currently the https://github.com/ethereum/web3.js/tree/1.0ES6 branch where we want to migrate to ES6, i think this is a good first step and should be done before thinking about typescript.

While I definitely prefer writing es6 over typescript, it can be nice for consumers of a library to have a typescript definition file published along with a module. It is a very detailed form of documentation that can be used by tools.

we have that

@frozeman I agree that there are type definitions but a lot of them are marked as any, which doesn't provide any type information at all.
I'd also be willing to volunteer for some help on this.

The library should be rewritten to Typescript for the following reasons:

  • Type safety! Dealing with smart contracts, making sure types are correct is a must!
  • Write code once in Typescript, then have it generate targets for ES3, ES5, ES6, ES7 ... Only one codebase!
  • Typings will be automatically generated and accurate. Always.

I think it would maybe also a good idea to use flow instead of typescript. I've ported web3 now to es6 and I think it would be much easier to get internal type safety with flow. 馃

I've ported web3 now to es6

That's great! TypeScript is a superset of ES6, so all that ES6 is already TypeScript!馃檪. This means you can gradually add types without having to type everything at once.

Here are some comments about TypeScript:

  • Faster
  • More type definitions
  • Bigger community
  • Open development
  • Better documentation

In my opinion, this is where the community is going. Big projects within Ethereum, such as EthereumJS are moving to TypeScript.

Here is a good comparison:
https://github.com/niieani/typescript-vs-flowtype

@jpeletier Thanks yes I know TypeScript well I was doing before internall cross platform mobile apps with it and I really like it. But I think it's always good to do some research and to have the proof that it is exactly what we want for this specific use case :)

Thanks for the comparsion I will definitely have a look at it!

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions

Was this page helpful?
0 / 5 - 0 ratings

Related issues

baxy picture baxy  路  3Comments

sundbry picture sundbry  路  3Comments

FradSer picture FradSer  路  3Comments

connectdotz picture connectdotz  路  3Comments

gabmontes picture gabmontes  路  3Comments