The static type checker FlowType supports the algebraic data types by encoding sums with disjoint unions of objects. However, Flow does not check if a switch
over a disjoint union is exhaustive. We present a trick to detect at compile-time these non-exhaustive switch
. Thus we can make sure that we do not miss any cases before putting our code into production.
At OuiCar, we use the static type checker FlowType to detect bugs in our Javascript applications. Since we have a lot of historical code or third party libraries, our code is a mix of typed Javascript and untyped Javascript. This can be the source of some subtle bugs, like runtime type errors in the typed code. We present a small assertion library in order to help to better embed untyped values in Flow programs.
Decode
We designed a Decode
library, whose code is given in the appendix below. The aim of the Decode
library is to dynamically check that some untyped value has some expected type. This is especially useful to check that our server API returns well-formed results.
We presented a talk at the Paris.js Meetup on the Elm architecture for the Javascript developer with Theophile Kalumbu and Guillaume Claret. The slides are available here (in French). Here is a translation of the abstract:
The web applications are more and more complex, and thus harder and harder to write and maintain. Moreover, due to the history of the Web, Javascript is often the only language we can use with all its known limitations.
At OuiCar, we try to take example on the Elm language and architecture, in order to better structure our existing code. Thanks to this approach, we are able to gradually make our code more robust and easier to maintain.
We will present our solutions and our remaining questions.
At OuiCar, we use the popular Redux-Form library to handle our forms in React and Redux. To get more confidence in our code, we use the FlowType type checker from Facebook. However, Redux-Form is a pure JavaScript library without Flow annotations. We present here how we managed to add some Flow types on Redux-From.
Flow is a type checker for JavaScript developed by Facebook. By adding type annotations to JavaScript programs, we get the safety and the simplicity of typed programming languages while staying in the JavaScript ecosystem. At OuiCar, we have been using the Flow type checker for over a month with great success. We present here some tips we found useful.
Declarations for the DOM and React
You can read the Flow declarations for the DOM and React in the sources of Flow itself. This is also an excellent source to learn Flow by the example.