如何在Typescript界面中强制使用分号

欧文·凯尔文(Owen Kelvin)

两者,(逗号)和;(分号)是有效的语法而宣告打字稿接口例如以下两者都是有效

export interface IUser {
  name: string;
  email: string;
  id: number;
}
export interface IUser {
  name: string,
  email: string,
  id: number
}

以下是我的关注,因为它也是有效的。的混合,;也适用

export interface IUser {
  name: string;
  email: string,
  id: number;
}

现在为了保持一致,我想;在所有场合都强制使用即使强制执行了分号规则,我的毛发也仍然可以通过typescript。任何想法如何实现?

.eslintrc.json

{
  "root": true,
  "ignorePatterns": [
    "projects/**/*"
  ],
  "overrides": [
    {
      "files": [
        "*.ts"
      ],
      "parserOptions": {
        "project": [
          "tsconfig.json",
          "e2e/tsconfig.json"
        ],
        "createDefaultProgram": true
      },
      "extends": [
        "plugin:@angular-eslint/ng-cli-compat",
        "plugin:@angular-eslint/ng-cli-compat--formatting-add-on",
        "plugin:@angular-eslint/template/process-inline-templates"
      ],
      "rules": {
        "@angular-eslint/component-selector": [
          "error",
          {
            "type": "element",
            "prefix": "app",
            "style": "kebab-case"
          }
        ],
        "@angular-eslint/directive-selector": [
          "error",
          {
            "type": "attribute",
            "prefix": "app",
            "style": "camelCase"
          }
        ]
      }
    },
    {
      "files": [
        "*.html"
      ],
      "extends": [
        "plugin:@angular-eslint/template/recommended"
      ],
      "rules": {}
    }
  ]
}

tsconfig.json

/* To learn more about this file see: https://angular.io/config/tsconfig. */
{
  "compileOnSave": false,
  "compilerOptions": {
    "baseUrl": "./",
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "downlevelIteration": true,
    "experimentalDecorators": true,
    "moduleResolution": "node",
    "importHelpers": true,
    "target": "es2015",
    "module": "es2020",
    "lib": [
      "es2018",
      "dom"
    ]
  }
}

湿婆潘迪

在.eslintrc文件中,添加以下提到的规则,

 "@typescript-eslint/member-delimiter-style": [
            "warn",
            {
                "multiline": {
                    "delimiter": "semi",
                    "requireLast": true
                },
                "singleline": {
                    "delimiter": "semi",
                    "requireLast": false
                }
            }
        ]

接受三个值(对于单行,则接受两个):

  • 逗号-每个成员应以逗号(,)分隔。

  • 分号-每个成员应以分号(;)分隔。

  • 无-每个成员之间都不应有任何分隔。

注–这不是单行的选项,因为在单行的成员之间没有定界符是TS中的语法错误。requireLast确定接口/类型中的最后一个成员是否应具有定界符:

  • true-最后一个成员必须具有定界符。
  • false-最后一个成员必须没有定界符。

参考链接:单击此处

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何在TypeScript界面中强制输入键类型?

Typescript + HTML:如何在输入字段中强制使用大写

如何在Typescript函数类型中强制使用强制性参数?

如何在Typescript的界面中将联合(或其他)类型设置为强制键名

如何在TypeScript界面中要求特定的字符串

如何在TypeScript界面中定义静态属性

如何在 Typescript 中深度扁平化界面?

如何在Typescript界面中引用自身类型(对于IClonable界面)

如何在coffeeScript中强制使用“ this”?

如何在codeigniter中强制使用ssl?

如何在Visual Studio Code中使用TypeScript和JavaScript禁用自动分号以进行自动导入?

如何在Typescript中强制参数为空对象

如何在Typescript中定义强制索引签名的泛型

如何在JSX / TSX中使用TypeScript强制转换

如何在ESLint for Javascript中禁用分号?

如何避免在Typescript React中重复界面

如何避免TypeScript中的重复界面

如何在不使用分号的情况下在 C 中打印“Hello”?

使用不带分号的'as'强制转换时出现TypeScript语法错误

如何在Xfce中更改语言界面?

如何在Android中隐藏用户界面

如何在改造界面中更改baseURL?

如何在GeckoFX中访问nsIHTMLEditor界面?

如何在界面中获取密钥类型

如何在Android中使用界面

如何在界面上使用Sscan

如何在CSS变量中强制使用整数?

如何在lodash /下划线中强制使用arity?

如何在gcc和VS中强制使用cmov