So I know you also use React extensively at twitch, so how are you finding react and typescript working together?
I've been using the two together recently and its been great. Like you I don't think I could ever go back to not using typescript for anything but the smallest projects.
However, often times I've found some common react patterns to be difficult to express in typescript. Namely default props and high order components. The type signatures I'v ended up with for my HoCs aren't as simple as I'd like, but I guess there is no way getting around that.
I've actually started to prefer render props over HoCs simply because the type signatures are simpler. Still no idea how to handle default props correctly.
I saw that for default props, but can I use it yet?
The React typescript definitions are still on 2.8 [1], and I imagine that they plan to stick with 2.8 until maybe the next major react release? I have no idea where people discuss things like react types for DefinitelyTyped. Github issues seem like a mess due to the sheer number of different projects sitting in a single repo.
Yeah you should be able to, the minimum typescript version required and the one they test at is 2.8 for now but the LibraryManagedAttributes type is present [1]. On 2.8 and 2.9 it has no effect but if you're using 3.0 you should see it working.
My pet peeve with TypeScript and React isn't with React but some parts of the ecosystem, like redux-saga: there are subtle issues with using the saga operators that mean that although the compiler makes it look like type inference is working, you've actually lost the type being ``taken`` from redux with redux-saga. To maintain type safety, you need to do funny things like "typeof sagaFunction".
Little things like this can add up to subtle bugs and tech debt if you're not careful.
I've been using the two together recently and its been great. Like you I don't think I could ever go back to not using typescript for anything but the smallest projects.
However, often times I've found some common react patterns to be difficult to express in typescript. Namely default props and high order components. The type signatures I'v ended up with for my HoCs aren't as simple as I'd like, but I guess there is no way getting around that.
I've actually started to prefer render props over HoCs simply because the type signatures are simpler. Still no idea how to handle default props correctly.