Fix placement of // @ts-expect-error comments in member chains - #19809
Open
santhiprakash wants to merge 4 commits into
Open
Fix placement of // @ts-expect-error comments in member chains#19809santhiprakash wants to merge 4 commits into
// @ts-expect-error comments in member chains#19809santhiprakash wants to merge 4 commits into
Conversation
When a comment like `// @ts-expect-error` is placed between the object and the property of a member expression continuation, it was being printed as a leading comment of the whole expression, hoisting it before the first member. This prevented TypeScript from seeing the directive on the line it is meant to suppress. Now the printer detects a comment located between `object` and `property` and prints it there, keeping the directive on the correct continuation line. Closes prettier#18121
commit: |
Contributor
Author
|
This PR is ready for review. The available token can create draft pull requests on prettier/prettier but does not have permission to call the markPullRequestReadyForReview GraphQL mutation (it requires contents:write on the upstream repo, which only collaborators have). Please mark it ready for review when convenient. |
6 tasks
β Deploy Preview for prettier ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
β Deploy Preview for prettier ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
β Deploy Preview for prettier ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
santhiprakash
marked this pull request as ready for review
August 16, 2026 20:51
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #18121
When a
// @ts-expect-errorcomment is placed on its own line before a member-chain continuation, Prettier was attaching it as a leading comment of the whole member expression and printing it before the first member. This moved the TypeScript directive away from the line it is meant to suppress.The member-expression printer now detects non-trailing comments located between
objectandpropertyand prints them before the lookup, keeping the directive on the correct continuation line.Verification
tests/format/typescript/comments/18121.tswith a Jest snapshot covering the reported case.yarn test tests/format/js tests/format/typescriptβ 25,509 tests passed.yarn test tests/format/typescript/comments/format.test.jsβ 104 tests passed.yarn lint:eslint src/language-js/print/member.js src/language-js/comments/will-print-own-comments.jspassed.yarn prettier --checkon changed files passed.yarn lint:changelogpassed.Checklist
docs/directory).changelog_unreleased/*/XXXX.mdfile followingchangelog_unreleased/TEMPLATE.md.