Skip to content

Renaming the discrimnant of a union should always rename all occurrences #21288

@RyanCavanaugh

Description

@RyanCavanaugh

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: ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptFixedA PR has been merged for this issue

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions