6

VS Code auto-completes JavaScript import {A...} as following:

import { Action } from './action.js';

I would like to change it to:
(remove spaces in the braces for import only)

import {Action} from './action.js';

Where can that be edited?

5
  • . @erosman does it autocomplets to that or formats to that? Do you use formatter and which one?\ Commented Jun 22, 2023 at 11:50
  • @Dimava Yes... After entering import {, it adds the closing braces and then after entering A it provides a selection, and after choosing Action, it changes {Action} to { Action } and automatically adds from './action.js'; Commented Jun 23, 2023 at 5:58
  • 1
    related issue ticket: github.com/microsoft/TypeScript/issues/15034 Commented Jun 28, 2023 at 3:29
  • Solution: github.com/microsoft/TypeScript/issues/… Commented Aug 27, 2024 at 10:54
  • @kishan-barmawala Thank you, that's the only thing that helped with this issue! Could you please post this as an answer so that more people notice it? Commented Sep 10, 2024 at 12:57

1 Answer 1

3

it's easy first of all open VS-Code then in the settings from the menu, search for javascript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces in the search bar and uncheck the box to disable it! then save it and restart VS-Code for the changes to take effect.

Update
open settings, then in the search bar, type editor.formatOnType and and check the box next to it.

Now, click on "Edit in settings.json" and add these lines:

"[javascript]": {
    "editor.formatOnType": true,
    "editor.formatOnPaste": true,
    "editor.formatOnSave": true,
    "editor.insertSpaces": false
},

as you can see editor.insertSpaces setting is set to false, which will prevent spaces from being inserted between the braces and the import statement! at the end save the changes and close it.

good luck !

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you but that is not the answer. I don't want to change the braces globally. I only want to change the import auto-complete.
javascript.preferences.importModuleSpecifier refers to the path and nothing to do with the format of the braces. See also: stackoverflow.com/a/51074467/3529456
I tested insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces and after unchecking, and even restarting, it didn't make any difference for the import in my example.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.