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

Setup TypeScript for the project #5424

Closed
christian-bromann opened this issue May 25, 2020 · 9 comments · Fixed by #5804
Closed

Setup TypeScript for the project #5424

christian-bromann opened this issue May 25, 2020 · 9 comments · Fixed by #5804
Assignees

Comments

@christian-bromann
Copy link
Member

Is your feature request related to a problem? Please describe.
As the code base is growing and the ecosystem leaning more and more towards TypeScript as type safe JavaScript flavor it makes sense to introduce it into the project as well. It help us grow the code base while at the same time reduce the amount of errors due to type issues.

Describe the solution you'd like
Let's get rid of Babel as compiler and replace it with TypeScript to start type safe programming. As we can't just rewrite the whole code base we should introduce a setup that allows us to continue to use our ESNext code while start writing new code in TypeScript.

Describe alternatives you've considered
Alternatively I considered just getting rid of Babel and convert everything to ES Modules (see #5401). However this can still be achieved with TypeScript.

Additional context
This discussion was triggered by #5399 and was discussed with the @webdriverio/technical-steering-committee. Everyone agreed that switching to TypeScript is a good idea. The reason why (particular myself) was hesitating towards this was that adding TypeScript to the code base increases the barrier for contributing to the project. However the code base increased in size which already creates a high barrier for people that aren't experienced enough.

@baruchvlz
Copy link
Member

introduce a setup that allows us to continue to use our ESNext code while start writing new code in TypeScript.

The TypeScript compiler has a flag, --allowJS, which compiles JavaScript files along side TypeScript files.

As we can't just rewrite the whole code base

We could also start re-writing the smaller modules and slowly progress to bigger ones.

Alternatively I considered just getting rid of Babel and convert everything to ES Modules (see #5401). However this can still be achieved with TypeScript.

tsc --module=ESNext should do the trick.

@erwinheitzman
Copy link
Member

I'm going to make a start on this if there are no objections

@erwinheitzman erwinheitzman self-assigned this May 25, 2020
@erwinheitzman
Copy link
Member

This evening I made a start with TypeScript where I have the @wdio/* paths and all other paths working without the use of a plugin (for now?). However I ran into a small challenge which I'd like to discuss with you all which is about the usage of the :: aka bind operator that's available through Babel.

Currently there's two ecmascript proposals for this functionality:

However both proposals are still in stage 1 and therefor will not be in the language anywhere soon.

Two solutions I can think of right now:

I'd love to hear your thoughts on this.

@christian-bromann
Copy link
Member Author

@erwinheitzman let‘s use the normal bind method given that the proposals haven’t made much progress.

@mgrybyk
Copy link
Member

mgrybyk commented May 26, 2020

I believe we can start refactoring package by package. It would be way easier to review

@erwinheitzman
Copy link
Member

yeah I am starting with the webdriverio package and migrate only a few small files but once I have it setup we should be able to reuse that across all packages

@christian-bromann
Copy link
Member Author

Let's keep the scope of this issue to setup TypeScript for all modules with minimal actual code rewrite after that we can start refactoring file by file.

@mgrybyk
Copy link
Member

mgrybyk commented Sep 3, 2020

@erwinheitzman do you think we can change the target from es5 to es2017?

I'd also insist on using a linter for TS files straight away, ex:

module.exports = {
  root: true,
  parser: '@typescript-eslint/parser',
  plugins: ['@typescript-eslint'],
  extends: [
    'eslint:recommended',
    'plugin:@typescript-eslint/eslint-recommended',
    'plugin:@typescript-eslint/recommended',
  ],
  env: {
    node: true,
    mocha: true,
  },
  rules: {
    '@typescript-eslint/explicit-function-return-type': 'off',
    '@typescript-eslint/member-delimiter-style': 'off',
  },
}

@christian-bromann
Copy link
Member Author

With #5804 we will get rid of Babel and therefor can close this.

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

Successfully merging a pull request may close this issue.

4 participants