5

How do you feel about using TypeScript with React? I appreciate the benefits, but, as every snippet of React code everywhere on the web is vanilla JS,I just don't want the cognitive overhead.

Yes, I know TS is JS, but, if I'm not going to use the features, why bother? I'd want to strongly type props, state, etc.

What's the status of TypeScript support in the React ecosystem (eg Router, MUI, etc.)?

I'm kinda hoping Reason will get some traction as the type inference is much better, but, will that happen? Or is that going to fizzle so it's a choice between TS and JS?

Appreciate any thoughts on this---including those from anyone who's in the same boat.

Looking for views on TS in React ecosystem---no need to sell me on TS in general.

Comments
  • 2
    If you are doing the bad redux react way of putting all state in one global place (nobody can convince me that this is not just a different way to use global variables) and not use the type system then yes, Typescript will not help you much.

    If you are otherwise willing to invest time in awesome type support and separating concerns and state into different files then Typescript is your savior.
  • 0
    But, in the Redux case you'd at least have typed actions, right?
  • 0
    @platypus True, but using types just for actions is not really using full potential of Typescript. They should be used everywhere and be thoroughly defined. Payoff from that is that you can have all of the autocompletion you want and exactly know with what types are you dealing with. :)
  • 0
    @arekxv actually I don't think redux has nothing to do with this subject. I would recommend typescript without any esitation.
    Then about redux. I do use redux (even in non react apps) and I configure it so that for each type of action TS knows what type the payload should be. If you use enums and interfaces correctly that's really not so complicated to achieve and is super convenient. To the point that in the switch statement in the reducers, for each case (action.type), TS knows what type is the action.payload.
  • 0
    @josap True, redux is something I do not like and it doesn't have much to do with typescript. But I've seen typescript getting used as vanilla JS a lot in redux so it was more of an example for me than anything else.

    But in summary, if you are prepared to use the type system and commit to it fully, typescript will help you. Otherwise, stick to standard JS :)
  • 0
    @arekxv agree 100%, TS really is a game changer if you commit to it fully
Add Comment