目录

@typescript-eslint/no-unsafe-return

Disallow returning a value with type any from a function.

This rule applies only to .js and .ts files.

Rule Configuration

// code-linter.json5
{
  "rules": {
    "@typescript-eslint/no-unsafe-return": "error"
  }
}

Options

This rule is not configurable.

Example of Correct Code

export function foo1(): string {
  return '1';
}

export function foo2(): object {
  return Object.create(null) as Record<string, unknown>;
}

export const foo3 = (): object[] => [];
export const foo4 = (): string[] => ['a'];

export function assignability1(): Set<string> {
  return new Set<string>(['foo']);
}

Example of Incorrect Code

export function foo1(): string {
  return '1' as any;
}

export function foo2(): string {
  return Object.create(null) as any;
}

export const foo3 = (): object[] => [] as any;
export const foo4 = (): string[] => ['a'] as any;

export function assignability1(): Set<string> {
  return new Set<string>(['foo']) as any;
}

Rule Set

plugin:@typescript-eslint/recommended
plugin:@typescript-eslint/all

For details about how to configure Code Linter check rules, see Code Linter.