Skip to content

Parenthesis break narrowing.Β #61784

Open
@JeanMeche

Description

@JeanMeche

πŸ”Ž Search Terms

  • narrowing
  • parenthesis
  • union
  • if condition
  • switch

πŸ•— Version & Regression Information

Tested in 5.8, probably not a regression.

⏯ Playground Link

https://www.typescriptlang.org/play/?#code/C4TwDgpgBAKhDOwoF5YOAQSgHzYgQgNwBQAlgHbAQBOAZgIYDG0ciWA3sVN1KJAFxQA5PSEkeUcvQC2EQYmoUA5iQC+xMpRoNmeYPiicJfOcIBGYrjwBu9ADYBXU+QfSzNNRtoPyjYKQB7cigAfWBGMwBGAApgAAtSeEF2XnRBViRVAEpDK24AenzYAGUoJQhyGnoqABMoMxAoDHIlBzt6aiF4WHBoAGE4iEYAa3q7AJG8qEYgxFDgSJQoaJWV+MSsgDoqRCytkz3xHlJaZbDF5EuoACJ6a5yjCR5VtYT4ffQ9zalZQ6hCqAAaQA8lN1FMAcUZNB6N16GYAtYIAAaKAAd1I8QCDiQ8WgYA6FTx8ESqMxXSgwMBUxm5DmYQATEt1vBtuhtr0jtwTmdgEzLqhbvdck9ni8WR9dlsfhBDmCNBCilDZCUoIlKYCoDTZrj0DBesy3mzEBzIFy1adYnqDQLhKIHlMJLT4AE7BBNuMlLEjTtgN9oVlzepVFAgA

πŸ’» Code

type Test = TestA | TestB;
interface TestA {
    type: 'a';
    name: string;
}

interface TestB {
    type: 'b';
    value: number;
}

function _tcb1(this: { test: Test }) {
    // TS generated by Angular's Type Check block
    const _t1 = (((((this).test)).type));
    if (_t1 === "a") {
        (((((this).test)).name)); // KO
    }
}

πŸ™ Actual behavior

TS doesn't narrow correctly

πŸ™‚ Expected behavior

TS should narrow correctly despite the execessive parenthesis.

Additional information about the issue

This is similar to a priori issue with typeof expressions #60784

Metadata

Metadata

Assignees

No one assigned

    Labels

    Help WantedYou can do thisPossible ImprovementThe current behavior isn't wrong, but it's possible to see that it might be better in some cases

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions