ChatGPT解决这个技术问题 Extra ChatGPT

WebStorm/PhpStorm double quotes in TypeScript auto import

I'm using TypeScript style with single quotes, double quotes are used exclusively in HTML templates.

WebStorm/PhpStorm auto import adds import statements with double quotes and ruins the style. I guess this applies to all JetBrains products.

How can this behaviour be fixed?

Like any other language in any JetBrains tool, alter the code style settings in your preferences.
That's true, just found it, where the answer suggests. There was nothing useful on 'quote' search in preferences.

L
Lovro Pandžić

This behaviour is controlled by the following option:

Settings/Preferences Editor | Code Style | TypeScript "Punctuation" tab | Generated code -> Quote marks

As of 2017.1 version it's on new Punctuation tab and options are named a bit differently:

https://i.stack.imgur.com/S94ry.png


If you started off on an older version of Intellij (< 2017.1), you may need to toggle the settings for it to actually apply. This was set to single quotes, but I was still seeing double quotes. It worked after changing to double quotes, applying, changing to single quotes, and finally applying again.
"Other" tab is now "Punctuation" - as of at least Webstorm 2017.3.2
@ggranum Yes, the screenshot and the note ("On 2017.1...") shows just that. I guess I better make it bold/more visible.
If you happen to use Vue.js with typescript, you may need to apply this setting for javascript as well. It seems that WebStorm does not apply typescript settings to Vue-files, even if they are set as lang=ts.
L
Leo

Also if you would like to add automatic space between curly braces when adding imports like so

import { MyComponent } from './my.component';

you may check in tab Spaces | Whithin | ES6 import/export braces


Thanks a lot! I was looking for that and it was extremely bothering me.
Same as Ivan, I had no idea how to customise this and Interpolation expressions as well. Thanks!
K
Kamil Witkowski

In 2017-2019 this is how we do it:

Go to settings Type Code style in search Select Typescript Go to Punctuation section Select single quotes

https://i.stack.imgur.com/34gmI.png


V
VinPro

https://i.stack.imgur.com/cQucq.png


Y
Yasir Shabbir Choudhary

1st Things need to check in your Tslint file

 "quotemark": [
  true,
  "Double"
],

It's should be Double rather than Single because it's Failed TSLint Passed on Project Build.

Now go to your Setting | Editor | TypeScript | Punctuation

Select Single from the dropdown and Apply/Ok it.

https://i.stack.imgur.com/VO436.png


关注公众号,不定期副业成功案例分享
Follow WeChat

Success story sharing

Want to stay one step ahead of the latest teleworks?

Subscribe Now