Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking β€œSign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
frigus02 opened this issue Nov 29, 2023 Β· 1 comment Β· Fixed by #56601
Closed
Labels
Bug A bug in TypeScript Help Wanted You can do this
Milestone

Comments

@frigus02
Copy link
Contributor

πŸ”Ž 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.

@nmain
Copy link

nmain commented Nov 29, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Help Wanted You can do this
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants