ts-migrate
ts-migrate copied to clipboard
Install @types packages as part of migrating
Following on from part of the discussion in #100, it would be really useful to install @types
packages automatically as part of a migration.
Some questions and ideas for how this might work:
Detect TS2307 and TS7016 diagnostics to decide which types packages would be useful. Alternatively, look through package.json
and try to resolve types for each package. This seems harder and more error-prone.
This seems like it may not fit in well with the existing plugin architecture. It doesn't transform source code, and it also seems like something you'd want to scan over all of your files and then run a single npm install
or yarn add
to install things. We could try to figure out how to extend the existing architecture, but I think I'd be inclined to start with a one-off implementation and see what other patterns and use cases emerge over time, if any.
How do we do the actual dependency installation? We'd need to detect npm/yarn/pnpm. Maybe there's a dependency we can pull in or other prior art.
How do we detect whether an appropriate types package exists?
How do we choose a version for the types package? Seems like it'd work in most cases to match up minor versions.
This is maybe too delayed to be helpful, but I'm wondering if you've seeing the package typesync. It is not perfect, but it works very well. It seems the lib tries to match minors, but if it can't makes the opinion of installing something rather than nothing.
My workflow as I've been migrating a handful of repositories has been to create a tsconfig.json
, (get all the other prerequisites like the ESLint plugins, etc), run npx tpyesync
, and then start migrating. Since this reads the package.json, this may also result in more types than you need (ex. I don't actually need @types/babel__core
), but this has been a great automated start for us.
I had not seen it! Thanks for pointing it out. That definitely seems like a better option than trying to roll something ourselves.
I wonder if there'd be a good way to incorporate it into the ts-migrate workflow. There doesn't appear to be an API; only a CLI. Options I can imagine:
- Mention it in documentation.
- Run it as part of
ts-migrate-full
- Create a
ts-migrate
subcommand. (This doesn't seem super useful since I imagine it would be equivalent tonpx typesync
.)
I definitely think the documentation is a good option, though it's made clumsy by the fact that one would have to run ts-migrate-full
then typesync
then ts-migrate reignore
. Alternatively someone could run ts-migrate init
, typesync
, ts-migrate migrate
.
Adding it to the ts-migrate-full
command would fix those issues, bringing with it the normal issues that come with dependencies: version management and misfiled issues. The github repo has over a thousand stars and only three issues. As far as dependencies/versioning goes, the last npm publish was a year ago, so it seems stable. There are 10 PRs open all by dependabot, yet no security advisories.
Any thoughts about what you'd like to do here? Can I offer documentation/development support?