6

Not very long time ago, Protractor itself migrated to TypeScript internally. I've also heard and seen several Protractor test projects moving to TypeScript.

We have a rather big and growing test codebase (about 22000 lines of JS code and 300 tests).

What benefits we might get if we switch to TypeScript? Is the migration work worth the cost?

2 Answers 2

5
+50

The nice thing of TypeScript you do not have to migrate at once. TypeScript is a superset and can parse plain JavaScript as well. You can keep your old code and start using TypeScript for new code or just some features. Read this story about gradually switching at Slack:

One of the reasons why the Slack team chose TypeScript is its being a superset of JavaScript, making it possible to adopt it without changing a single line of code and then gradually enabling its code analysis features and including the type definitions available for many popular packages.

https://www.infoq.com/news/2017/04/going-typescript-slack

Pro's:

  • I have you multiple developers you might benefit from having static-types in your pageObjects for example.
  • If the developers use TypeScript everywhere else in the project I would switch, as it minimises context switching of the languages.
  • Easier to build decoupled code with interfaces, could be handy on large complex test-code-bases.
  • Better syntax completion, due to types the IDE knows all it properties and methods.

Con's:

  • Add's an extra layer of complexity, extra build steps, more things that can go wrong.
  • Not sure the types are of real added value in tests. Test code "checks" itself, if the code does not work the test will fail. Which means you will need check what is going on anyways.
  • Googling will be harder as not a lot of users use TypeScript. This always holds me back to switch to less popular frameworks. (only 9.5% of the developers use it in the SO-2017 survey.)

Other reads:

4
+100

NO.

I would not suggest doing so until you have a specific objective to be met by doing it.

In my opinion, its only worth the effort if you are working on large development project but for comparatively smaller UI automation projects with less than 1K tests, I would not suggest so.

Also, there are a lot of misconceptions about the advantages of moving from javaScript to TypeScript:

  • Object-oriented Features:- Like types/classes, we may use many of these features natively from ES6 in javaScript and we can transpile down with Babel if required.
  • Easier than JavaScript: It is not. It is still a superset of JavaScript, in fact, additional type noise particularly for UI test automation.
  • Strong typing means error proof: Strong typing only safeguards a certain class of errors but not all the errors and at the cost of extraneous syntax which is an overkill for UI test automation.

As far as static type checking as a feature is concerned, it can also be achieved using Facebook’s Flow.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.