Disallow void type outside of generic or return types.
// code-linter.json5
{
"rules": {
"@typescript-eslint/no-invalid-void-type": "error"
}
} 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; // 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;
} plugin:@typescript-eslint/all
For details about how to configure Code Linter check rules, see Code Linter.