Skip to content
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

Can't format typescript types file #286

Open
cnhongwei opened this issue Mar 8, 2024 · 1 comment
Open

Can't format typescript types file #286

cnhongwei opened this issue Mar 8, 2024 · 1 comment

Comments

@cnhongwei
Copy link

Your Environment

  • Prettier version: 2.8.8
  • node version [16.20.1]:
  • package manager: [yarn@2]
  • IDE: [idea]

Describe the bug

format a file lingui.d.ts

declare module "*.po" {
  const messages: {
    [key: string]: string;
  };
  export { messages };
}

To Reproduce
yarn prettier --write lingui.d.ts

[error] lingui.d.ts: SyntaxError: Export 'messages' is not defined. (5:11)
[error]   1 | declare module "*.po" {
[error]   2 |   const messages: {
[error]   3 |     [key: string]: string;
[error]   4 |   };
[error]   5 |   export { messages };
[error]   6 | }
[error]   7 |
error Command failed with exit code 2.

Using IDEA for formatting, the same error is obtained.

SyntaxError: Export 'messages' is not defined. (5:14)
�[0m �[90m 1 |�[39m declare module �[32m"*.po"�[39m {�[0m
�[0m �[90m 2 |�[39m   �[36mconst�[39m messages�[33m:�[39m {�[0m
�[0m �[90m 3 |�[39m     [key�[33m:�[39m string]�[33m:�[39m string�[33m;�[39m�[0m
�[0m �[90m 4 |�[39m   }�[33m;�[39m�[0m
�[0m �[90m 5 |�[39m      �[36mexport�[39m { messages }�[33m;�[39m�[0m
�[0m �[90m 6 |�[39m }�[0m
�[0m �[90m 7 |�[39m�[0m
    at instantiate (xxx/node_modules/@babel/parser/lib/index.js:63:32)
    at constructor (xxx/node_modules/@babel/parser/lib/index.js:358:12)
    at TypeScriptParserMixin.raise (xxx/node_modules/@babel/parser/lib/index.js:3255:19)
    at TypeScriptParserMixin.parseProgram (xxx/node_modules/@babel/parser/lib/index.js:12463:14)
    at TypeScriptParserMixin.parseTopLevel (xxx/node_modules/@babel/parser/lib/index.js:12450:25)
    at TypeScriptParserMixin.parse (xxx/node_modules/@babel/parser/lib/index.js:14345:10)
    at TypeScriptParserMixin.parse (xxx/node_modules/@babel/parser/lib/index.js:10024:18)
    at parse (xxx/node_modules/@babel/parser/lib/index.js:14386:38)
    at preprocessor (xxx/node_modules/@trivago/prettier-plugin-sort-imports/lib/src/preprocessors/preprocessor.js:15:34)
    at Object.defaultPreprocessor [as preprocess] (xxx/node_modules/@trivago/prettier-plugin-sort-imports/lib/src/preprocessors/default-processor.js:9:44)

Expected behavior

Able to format correctly.

Configuration File (cat .prettierrc, prettier.config.js, .prettier.js)

{
"importOrder": [
"^react(\/[^\\/]+)?$",
"^react-dom(\/[^\\/]+)?$",
"^react-native(\/[^\\/]+)?$",
"^next(\/[^\\/]+)?$",
"<THIRD_PARTY_MODULES>",
"^[./]"
],
"importOrderSeparation": true,
"importOrderSortSpecifiers": true,
"importOrderGroupNamespaceSpecifiers": true,
"xmlWhitespaceSensitivity": "ignore"
}

@HiroAgustin
Copy link

Same as #213

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants