no-invalid-void-type
Configuration
Rule Details
Disallows void type outside of generic or return types. The void type in TypeScript means a function returns nothing, and is only meaningful as a return type of functions, methods, callable signatures, construct signatures, or as a generic type argument (e.g., Promise<void>). Using void in other positions such as variable types, parameter types, or union types is typically a mistake and can lead to confusing behavior.
Examples of incorrect code for this rule:
Examples of correct code for this rule:
Options
allowInGenericTypeArguments
- Type:
boolean | string[] - Default:
true
When true (default), allows void as a type argument in any generic type (e.g., Promise<void>, Map<string, void>).
When set to an array of strings, only allows void as a type argument in the listed generic types. Supports dotted names (e.g., ['Promise', 'Ex.Mx.Tx']).
When false, void is only valid as a direct return type.
allowAsThisParameter
- Type:
boolean - Default:
false
When true, allows void as the type of a this parameter in functions and methods.