Mastodon hachyterm.io

Today I finished my first TypeScript experiment with React.

Here are some thoughts after using ReasonReact first, and now TypeScript second.

  1. Setup Is Not Better Than ReasonReact

    I used Create React App to bootstrap the app.

    npx create-react-app <project-name> --typescript
    

    But then I had to setup ESLint and Prettier with TypeScript.

    ReasonML & BuckleScript:

    npm install -g bs-platform
    bsb -init <project-name> -theme react-hooks
    

    After that you’re done.

  2. It’s JavaScript

    ReasonML is a completely different language than JavaScript. Don’t let the similar syntax fool you.
    TypeScript is “enhanced” JavaScript.

    TypeScript is “easier”, at least at the beginning.

  3. The React+TypeScript CheatSheets Are Invaluable

    You should use them.

  4. How Do I Get 100% Type-Safety?

    How do you “make impossible states impossible”?

    You’ll soon have to reach for advanced concepts like Discriminated Unions. Those are quite more complicated than their ReasonML equivalent.

    And how do you type Promises?

    It’s incredibly difficult to reach 100% type safety for a beginner. ReasonML provides a better story here.

  5. The Code Is Hard To Read

    Type inference doesn’t work as well as in ReasonML/OCaml. As a consequence, you have to define types explicitly.

    The code is quite verbose and harder to read.

Further Reading