src/content/docs/linter/rules/no-confusing-void-type.mdx
import { Tabs, TabItem } from '@astrojs/starlight/components';
<Tabs> <TabItem label="TypeScript and TSX" icon="seti:typescript"> ## Summary - Rule available since: `v1.2.0` - Diagnostic Category: [`lint/suspicious/noConfusingVoidType`](/reference/diagnostics#diagnostic-category) - This rule is **recommended**, meaning it is enabled by default. - This rule has an [**unsafe**](/linter/#unsafe-fixes) fix. - The default severity of this rule is [**warning**](/reference/diagnostics#warning). - Sources: - Same as [`@typescript-eslint/no-invalid-void-type`](https://typescript-eslint.io/rules/no-invalid-void-type){
"linter": {
"rules": {
"suspicious": {
"noConfusingVoidType": "error"
}
}
}
}
Disallow void type outside of generic or return types.
void in TypeScript refers to a function return that is meant to be ignored.
Attempting to use a void type outside of a return type or a type parameter is often a sign of programmer error.
void can also be misleading for other developers even if used correctly.
The
voidtype means cannot be mixed with any other types, other thannever, which accepts all types. If you think you need this then you probably want theundefinedtype instead.
The code action suggests using undefined instead of void.
It is unsafe because a variable with the void type cannot be assigned to a variable with the undefined type.
let foo: void;
function logSomething(thing: void) {}
interface Interface {
prop: void;
}
type PossibleValues = number | void;
function foo(): void {};
function doSomething(this: void) {}
function printArg<T = void>(arg: T) {}