-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Automated Migration for Breaking Changes to the Type System #33345
Comments
This is cool, I'd also like to see the same on a per-flag basis, e.g. |
If we think it's possible and useful, we do build quickfixes for the editor for these kinds of things (though we still don't have a tool to run fixes from the command line @DanielRosenwasser ). We just don't always bother - the |
To throw this out there: I think #13195 would be something that needs automated migration. Though, there are multiple other blocking features associated with that issue. |
Should I close this issue, given that this sort of thing is in the works already per Wes' comment? #33345 (comment) |
I mean, I'd leave that to @DanielRosenwasser, as he's been looking for a reason to build out the quickfixes-on-the-commandline feature for forever. |
Broadly speaking there are two distinct categories of things to consider here:
An example Type I break would be An example Type II break would be the We can create Quick Fixes for Type I errors, and typically do. These also tend to be very well-documented and well-thought-out changes because they're typically the "We are breaking you on purpose" kind of breaking change. Many Type I breaks are also associated with a commandline flag to turn them off. For a Type II error, even if we could figure out what happened, often there's no "quick fix" because it depends on what the code was trying to do in the first place, and the change that does need to occur might be very lexically far away from where the first actual type error is issued. We can provide tooling all day long for Type I breaks, but I would argue that this is a bit of a low-value activity. These breaks are often not particularly painful, are signaled well in advance, and usually have a simple commandline fix or can be bulk-addressed by a sufficiently clever RegExp. Adopting something like Facebook's Type II breaks are vexing. Often we don't even really know we're making them - the For example, let's say you wrote some code const arr = [1, 2, 3, "four", "five"];
const arr2 = arr.filter(x => +x === x);
arr2.push("six"); Maybe in the future, TS gets smarter and says In even the most trivial example, the error is very causally disconnected from the original change, and it's not even clear what the right "fix" to issue is. What it seems like you want for Type II errors is just a tool that runs const arr = [1, 2, 3, "four", "five"];
const arr2 = arr.filter(x => +x === x);
// @ts-ignore Error 'cannot convert "six" to 'number'" introduced in TS 4.2
arr2.push("six"); vs const arr = [1, 2, 3, "four", "five"];
// TODO: Multiple errors involving 'arr2' introduced in TS 4.2
const arr2: any = arr.filter(x => +x === x);
arr2.push("six");
arr2.push("seven");
arr2.push("eight"); |
I feel that quick fixes, more often than not, are often fairly low-effort and help educate users more about the breaks themselves and how to fix them. So I don't believe it's low-value, and even if it is, the effort isn't unreasonable in the first place. |
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 #33272
Use Cases
The changes described in #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
tsc --upgrade --from=3.5 --to=3.6 example.ts
The example is from #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:
The text was updated successfully, but these errors were encountered: