TypeScript at Redgate
All programming languages have their own flaws but JavaScript is especially notorious about its unique flaws. It’s a common thing that JavaScript manages to let us down at run-time due to coercion or a syntactical mistake. That’s why there are questions like Why is [1,2] + [3,4] = “1,23,4” in JavaScript? in the wild.
Most of the developers’ nightmare just starts with Uncaught TypeError: Cannot read property “bar" of undefined
and continues with Uncaught TypeError: undefined is not a function
. There are many other examples of JavaScript run-time errors and weirdness on the web — Here’s one of them:
To avoid all these run-time craziness, we decided to port SQL Clone Web Client to TypeScript.
TypeScript is not the only option to avoid all the craziness — there is a great list of languages that transpile to JavaScript. You should choose the one that meets your needs.
Porting to TypeScript
Our initial thought on what we want to achieve was that we make it as hard as possible to add obscure bugs, ease of refactor safely and quickly. We wanted to do this without slowing down development process in other ways with a ton of boilerplate and twisting in knots to satisfy a type system like we often do in C#. Basically, we wanted to embrace the good things about scripting languages without settling for all the bad things. In terms of other constrains, the language we pick should not be completely dissonant with C# and/or JavaScript as a language.
Along with language features, the editor integration was very crucial for us. Thanks to TypeScript’s language API, editors support the development with context-aware suggestions. Modules written in TypeScript can enable editors to suggest usage hints.
What about React?
Tugberk mentioned in his previous blog post that SQL Clone Web Client is our biggest React & Redux application at Redgate. We love using React because of its declarative approach on creating user interfaces. So, how well does TypeScript understand React?
Luckily, TypeScript ships with JSX
support out of the box. The only thing we need to do is installing React typing in order to use JSX
with React.
Learning TypeScript
There are many resources online for learning TypeScript. The official documentation itself includes great learning material, making it easy to get started. If you’d like to dive into TypeScript right now, just go to the playground and spend some time in there.
Want to work at Redgate?
If using modern web technologies with native code to build a Windows desktop app sounds exciting to you, come work with us! We are hiring!