-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
incorrect formatting of JSDoc type assertion by JS parsers other than babel-*
#8171
Comments
It's a known issue. See the release notes for 2.0. TypeScript, the language, doesn't support such type casts. TypeScript, the compiler, supports them only in JS. Check this playground: declare const foo: any;
const bar1 = /** @type {string} */(foo);
|
People might have reasons to use |
No problem! I was just raising it because of the attached issue that someone raised - in testing I realised that prettier munges it. I think we might need to add support for at least this case to the parser, which would fix the issue here as well. |
I didn't know the BTW, it'd be interesting if the parser exposed the |
Yeah (almost) all of our rules work fine on JS code. If you're good with your jsdoc typing, ones that use type information will even work pretty well! Unfortunately it looks like JSDoc will never be an official part of the ESTree spec (estree/estree#201), but there's no reason we couldn't consider exposing it, given that it's parsed as an AST by TS itself. |
This comment was marked as off-topic.
This comment was marked as off-topic.
babel-*
Related issue in the parser repos: |
Prettier 2.0.5
Playground link
# Options (if any): --parser typescript
Input:
Output:
Expected behavior:
What's wrong?
In a JS Codebase, dropping the parens breaks the JSDoc type assertion, which will break type checking.
See deeper explanation in typescript-eslint/typescript-eslint#1943
It looks like this only occurs with the typescript parser, as the babel parser works correctly (though note that the
flow
parser exhibits the same paren scrubbing behaviour).Related issues (not exactly the same, but pertaining to JSDoc in TS): #8045, #5850
The text was updated successfully, but these errors were encountered: