文档管理中心
指南编写与调试应用代码编辑代码检查Code Linter代码检查规则通用规则@typescript-eslint@typescript-eslint/no-explicit-any

@typescript-eslint/no-explicit-any

不允许使用“any”类型。

该规则仅支持对.js/.ts文件进行检查。

规则配置

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

正例

收起
自动换行
深色代码主题
复制
  1. export const age1 = 17;
  2. export const age2 = [age1];
  3. export const age3 = [age1];
  4. export function greet1(): string {
  5. return 'greet';
  6. }
  7. export function greet2(): string[] {
  8. return ['greet'];
  9. }
  10. export function greet4(): string[][] {
  11. return [['greet']];
  12. }
  13. export function greet5(param: readonly string[]): string {
  14. return param[age1];
  15. }
  16. export function greet6(param: readonly string[]): string[] {
  17. return [...param];
  18. }

反例

收起
自动换行
深色代码主题
复制
  1. export const age1: any = 17;
  2. export const age2: any = [age1];
  3. export const age3: any = [age1];
  4. export function greet1(): any {
  5. return 'greet';
  6. }
  7. export function greet2(): any[] {
  8. return ['greet'];
  9. }
  10. export function greet4(): any[][] {
  11. return [['greet']];
  12. }
  13. export function greet5(param: readonly any[]): any {
  14. return param[age1];
  15. }
  16. export function greet6(param: readonly any[]): any[] {
  17. return [...param];
  18. }

规则集

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

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

在 指南 中进行搜索
请输入您想要搜索的关键词