新版本的变更 / TypeScript 4.4

// *** before: ***
interface Circle { kind: "circle"; radius: number; }
interface Square { kind: "square"; side: number; }
function area(shape: Circle | Square) {
    const isCircle = shape.kind === "circle";
    if (isCircle) {
        // shape всё ещё Circle | Square - сужение не проходило через переменную
        return Math.PI * (shape as Circle).radius ** 2;
    }
    return (shape as Square).side ** 2;
}

// *** in version 4.4: ***
function areaNarrowed(shape: Circle | Square) {
    const isCircle = shape.kind === "circle";
    if (isCircle) {
        return Math.PI * shape.radius ** 2// shape сужен до Circle
    }
    return shape.side ** 2// shape сужен до Square
}