Skip to content

noConfusingVoidType (since v1.2.0)

Diagnostic Category: lint/suspicious/noConfusingVoidType

Source: no-invalid-void-type

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 generic type argument is often a sign of programmer error. void can also be misleading for other developers even if used correctly.

The void type means cannot be mixed with any other types, other than never, which accepts all types. If you think you need this then you probably want the undefined type instead.

let foo: void;
suspicious/noConfusingVoidType.js:1:10 lint/suspicious/noConfusingVoidType ━━━━━━━━━━━━━━━━━━━━━━━━━

   void is only valid as a return type or a type argument in generic type
  
  > 1 │ let foo: void;
            ^^^^
    2 │ 
  
   Remove void
  
function logSomething(thing: void) {}
suspicious/noConfusingVoidType.js:1:30 lint/suspicious/noConfusingVoidType ━━━━━━━━━━━━━━━━━━━━━━━━━

   void is only valid as a return type or a type argument in generic type
  
  > 1 │ function logSomething(thing: void) {}
                                ^^^^
    2 │ 
  
   Remove void
  
interface Interface {
prop: void;
}
suspicious/noConfusingVoidType.js:2:11 lint/suspicious/noConfusingVoidType ━━━━━━━━━━━━━━━━━━━━━━━━━

   void is only valid as a return type or a type argument in generic type
  
    1 │ interface Interface {
  > 2 │     prop: void;
             ^^^^
    3 │ }
    4 │ 
  
   Remove void
  
type PossibleValues = number | void;
suspicious/noConfusingVoidType.js:1:32 lint/suspicious/noConfusingVoidType ━━━━━━━━━━━━━━━━━━━━━━━━━

   void is not valid as a constituent in a union type
  
  > 1 │ type PossibleValues = number | void;
                                  ^^^^
    2 │ 
  
   Remove void
  
function foo(): void {};
function doSomething(this: void) {}
function printArg<T = void>(arg: T) {}