Skip to content

Leading comment and trailing type assertion in return incorrectly remove load bearing parentheses #56591

Closed
@frigus02

Description

@frigus02

πŸ”Ž Search Terms

return, parens, parenthesis, assertion

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried: v5.2.2, v5.3.2, v5.4.0-dev.20231129

⏯ Playground Link

https://www.typescriptlang.org/play?ts=5.3.2#code/KYDwDg9gTgLgBAYwDYEMDOa4DEITgbwFgAoORJAS2ADt4BeAkssgc2BgBUALC6lgLjgAKAJRw6APjgAFKBAC2FNMAB0UYGghIAbsCEByfSKZwAviRMAzXKMGyFS4AB5tECgBMpRUs3UwArlDUwibMcAD0AFRwHADyACKxggCCrh5w-mi8LHAwAJ5gwHDoyrAUENRoADRwYEjA6EXqligIMNAqcJHhuTxoKshUtKFhcCpsnDx8osWY-tQA1tQQAO7B6DJyisoubp4jIgDcJubEp0A

πŸ’» Code

export class Foo {
  client = {
    getThing: () => Promise.resolve('')
  }

  foo(): Promise<void> {
    return (
      /* TODO: Avoid using type assertions, please refactor. */ this.client
        .getThing() as unknown as Promise<void>
    );
  }
}

πŸ™ Actual behavior

export class Foo {
    constructor() {
        this.client = {
            getThing: () => Promise.resolve('')
        };
    }
    foo() {
        return 
        /* TODO: Avoid using type assertions, please refactor. */ this.client
            .getThing();
    }
}

This means new Foo().foo() essentially returns undefined.

πŸ™‚ Expected behavior

    foo() {
        return (
        /* TODO: Avoid using type assertions, please refactor. */ this.client
            .getThing());
    }

Additional information about the issue

This happens specifically when the return statement begins with a comment and ends with a type assertion.

Activity

nmain

nmain commented on Nov 29, 2023

@nmain

load bearing parentheses

I congratulate you on inventing a brand new term (at least, I can't find any mention of it on Google anywhere), yet one that is immediately understandable to a reader who has never heard it before.

added this to the Backlog milestone on Nov 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptHelp WantedYou can do this

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Participants

      @frigus02@RyanCavanaugh@nmain

      Issue actions

        Leading comment and trailing type assertion in return incorrectly remove load bearing parentheses Β· Issue #56591 Β· microsoft/TypeScript