-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Renaming the discrimnant of a union should always rename all occurrences #21288
Copy link
Copy link
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptFixedA PR has been merged for this issueA PR has been merged for this issue
Milestone
Description
TypeScript Version: master
Search Terms: rename all locations find references discriminated union
Code
type Result =
{ kind: "success", code: number } | // 1
{ kind: "failure", message: string }; // 2
function fn(): Result {
if (Math.random() > 0.5) {
return { kind: "failure", message: "oops" } // 3
} else {
return { kind: "success", code: 200 } // 4
}
}
const r = fn();
if (r.kind === "failure") { // 5
r.message;
} else if (r.kind === "success") { // 6
r.code;
}There are 6 occurrences of kind in this program (annotated above); renaming at locations 1 and 2 does not produce an error-free program, locations 3 and 4 do, location 5 does, but location 6 does not.
Playground Link: link
Related Issues: ?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptFixedA PR has been merged for this issueA PR has been merged for this issue