paul
paul
TTCTheo's Typesafe Cult
Created by paul on 7/6/2023 in #questions
Challenging recursive TS type
Had an annoying time with this one today at work. See this playground for repro: https://t.ly/C--h One of my APIs has a quirk that the JSON it provides gives every object back wrapped in a surrounding { map: <obj> }. I can write a simple recursive function to mapWrap some data, or to unMapWrap it when I receive it. I can also define a generic type that expresses the relationship between a MapWrapped<T> and the unwrapped type. But I don't know how to make TS understand that the mapWrap<T> function produces the MapWrapped<T> type without casting to any multiple times.
2 replies
TTCTheo's Typesafe Cult
Created by paul on 12/25/2022 in #questions
Old codebase, outdated tool chain - how to limit the blast?
I have a 5-6 year-old enterprisey React codebase at work with a bunch of dependencies that for the most part haven't been upgraded since the day they were first installed. Most of the build chain is two+ major versions behind current: webpack 3, babel (& all loaders/plugins) v6, from before the monorepo reorg, Jest v23, and Flow 🤦 version 0.37. For those who haven't been keeping up with Flow (and who has?) the current version is 0.195.0. It's so old that the flow-language-server in vs code won't start, and the Stripe flow-to-typescipt-codemod works only partially and leaves several thousand compiler errors that it can't address. Oh, and it's also an ejected create-react-app codebase with a lot of custom build scripts and a really bespoke end-to-end testing setup that I don't pretend to understand. Anyone who understood this codebase has long since moved on. Right now I'm as expert as anyone else here, and I have the team's blessing to take the reins and upgrade this all to a modern stack. But as I experiment with it, it's a pile of pickup sticks, because anything I pull on seems to require me to upgrade everything else. Target state is Typescript replacing Flow, and either Vite and Vitest replacing the rest of the toolchain— or if that's impossible, at least modern versions of Webpack and Jest. Question for the channel, as per title: is there any way to avoid a big rewrite that takes a month and breaks a bunch of things I don't know about? Anybody have experience with something similar?
25 replies