microsoft / microsoft/TypeScript

Automated Migration for Breaking Changes to the Type System

Open
#33,345 7 comments 11 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Needs Proposal Suggestion
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

Automated Migration for Breaking Changes to the Type System

Search Terms

codemod, migration, upgrade

Suggestion

semi-automated migration when there are breaking changes in the type system

One way of implementing this would be via codemods (could use the TS Compiler API) that do trivial update tasks as described in https://github.com/microsoft/TypeScript/issues/33272

Use Cases

  • Would make it easier for users to upgrade to the latest TypeScript
  • Would make it easier for the TS team to upgrade TypeScript
  • Might enable TS to evolve faster, as the pain from these "breaking" changes will be smaller

The changes described in https://github.com/microsoft/TypeScript/issues/33272, for example, were mostly trivial, and ideally would not need much human intervention.

Type-only changes are especially amenable to this kind of treatment, because no one's app will misbehave at runtime if there is a bug in the transformation.

I say 'semi-automated' because in cases where the tool can't figure out the problem, the tool could yield to human judgment. Tooling for this doesn't have to be perfect, but a small amount of automation could go a long way.

Examples

example.ts

const myPromise: Promise<{}> = dontCarePromise();

tsc --upgrade --from=3.5 --to=3.6 example.ts

const myPromise: Promise<unknown> = dontCarePromise();

The example is from https://github.com/microsoft/TypeScript/issues/33272.

In a case where the conversion would lead to a new type error, I'd expect the tool to bail out, explain the situation, and let the human decide what to do.

Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the breaking changes described in TypeScript issue 33272 and reviewing the TypeScript Compiler API as the proposed basis for codemods. Define which type-only migrations can be automated, how the tool reports cases that would introduce errors, and how users invoke it. Done means a scoped migration design with a clear boundary between automated transformations and human decisions.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.