TypeScript 自动导入中的 WebStorm/PhpStorm 双引号

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39779272/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 07:21:50  来源:igfitidea点击:

WebStorm/PhpStorm double quotes in TypeScript auto import

typescriptintellij-ideaphpstormwebstormjetbrains-ide

提问by Estus Flask

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

我使用带单引号的 TypeScript 样式,双引号专门用于 HTML 模板。

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

WebStorm/PhpStorm 自动导入添加了import带双引号的语句并破坏了样式。我想这适用于所有 JetBrains 产品。

How can this behaviour be fixed?

如何修复这种行为?

回答by LazyOne

This behaviour is controlled by the following option:

此行为由以下选项控制:

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


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

从 2017.1 版本开始,它位于新Punctuation选项卡上,选项的名称略有不同:

enter image description here

在此处输入图片说明

回答by Leo

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

此外,如果您想在像这样添加导入时在花括号之间添加自动空格

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

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

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

你可以签入标签 Spaces | Whithin | ES6 import/export braces

回答by Kamil Witkowski

In 2017-2019this is how we do it:

2017-2019这是我们如何做到这一点:

  1. Go to settings
  2. Type Code stylein search
  3. Select Typescript
  4. Go to Punctuationsection
  5. Select singlequotes
  1. 前往设置
  2. 类型Code style搜索
  3. 选择 Typescript
  4. 转到Punctuation部分
  5. 选择single报价

enter image description here

在此处输入图片说明

回答by Yoraco Gonzales

Punctuation Tab did it. I also removed the semicolon at the end but now TSLint is missing it

标点标签做到了。我还删除了最后的分号,但现在 TSLint 缺少它

回答by VinPro

For Intellij 2016.3 version it's on Other Tab > Generated Code > Quote Marksenter image description here

对于 Intellij 2016.3 版本,它位于其他选项卡 > 生成的代码 > 引号在此处输入图片说明

回答by Yasir Shabbir Choudhary

1st Things need to check in your Tslint file

第一件事需要检查你的 Tslint 文件

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

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

它应该是 Double 而不是 Single,因为它在项目构建时失败了 TSLint 传递。

Now go to your Setting | Editor | TypeScript | Punctuation

现在去你的设置 | 编辑 | 打字稿 | 标点

Select Single from the dropdown and Apply/Ok it.

从下拉列表中选择 Single 并应用/确定它。

Now Congrats your IntellijIDEA are applied Double Quotes on AutoImport.For reference

现在恭喜您的 IntellijIDEA 在 AutoImport 上应用了双引号。以供参考