目录

@typescript-eslint/no-invalid-void-type

Disallow void type outside of generic or return types.

Rule Configuration

// code-linter.json5
{
  "rules": {
    "@typescript-eslint/no-invalid-void-type": "error"
  }
}

Options

For details, see @typescript-eslint/no-invalid-void-type.

Example of Correct Code

export type NoOp = () => void;
export function noop(): void {
  console.info('noop');
}
export const trulyUndefined = void Number.MAX_VALUE;
export async function promiseMeSomething(): Promise<void> {
  return Promise.reject('value').catch(() => {
    console.error('error');
  });
}
export type StillVoid = void | never;

Example of Incorrect Code

// The void type is not allowed.
export type PossibleValues = string | number | void;
// The void type is not allowed.
export type MorePossibleValues = string | (string | void);

// The void type is not allowed.
export function logSomething(thing: void) {
  return thing;
}
export function printArg<T = void>(arg: T) {
  return arg;
}

export interface Interface {
  lambda: () => void;
  // The void type is not allowed.
  prop: void;
}

Rule Set

plugin:@typescript-eslint/all

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