文档管理中心
我的
工具开发工具DevEco Studio(鸿蒙电脑版)编写与调试应用代码编辑代码检查Code Linter代码检查规则通用规则@typescript-eslint@typescript-eslint/array-type

@typescript-eslint/array-type

定义数组类型时,建议使用相同的样式。比如都使用T[]或者都使用Array<T>。

规则配置

收起
自动换行
深色代码主题
复制
  1. // code-linter.json5
  2. {
  3. "rules": {
  4. "@typescript-eslint/array-type": "error"
  5. }
  6. }

选项

详情请参考typescript/array-type 选项。

正例

收起
自动换行
深色代码主题
复制
  1. const x: string[] = ['a', 'b'];
  2. const y: readonly string[] = ['a', 'b'];
  3. export { x, y };

反例

收起
自动换行
深色代码主题
复制
  1. const x: Array<string> = ['a', 'b'];
  2. const y: ReadonlyArray<string> = ['a', 'b'];
  3. export { x, y };

规则集

收起
自动换行
深色代码主题
复制
  1. plugin:@typescript-eslint/all

Code Linter代码检查规则的配置指导请参考Code Linter代码检查。