{"record":{"id":"5ef659b275fba8b9","repo":"oxc-project/oxc","slug":"use-void-only-as-a-return-type-generic-type-arg","errorCode":null,"errorMessage":"Use `void` only as a return type, generic type argument, or the type of a `this` parameter.","messagePattern":"Use `void` only as a return type, generic type argument, or the type of a `this` parameter\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/typescript/no_invalid_void_type.rs","lineNumber":53,"sourceCode":"\nfn invalid_void_not_return_or_generic_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Use `void` only as a return type or generic type argument.\")\n        .with_help(\n            \"Replace this `void` type with an allowed type, or keep `void` only in a valid return position.\",\n        )\n        .with_label(span)\n}\n\nfn invalid_void_not_return_or_this_param_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Use `void` only as a return type or as the type of a `this` parameter.\")\n        .with_help(\n            \"Replace this `void` type with an allowed type, or keep `void` only in a valid return position.\",\n        )\n        .with_label(span)\n}\n\nfn invalid_void_not_return_or_this_param_or_generic_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\n        \"Use `void` only as a return type, generic type argument, or the type of a `this` parameter.\",\n    )\n    .with_help(\n        \"Replace this `void` type with an allowed type, or keep `void` only in a valid return position.\",\n    )\n    .with_label(span)\n}\n\nfn invalid_void_union_constituent_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Remove `void` from this union type constituent.\")\n        .with_help(\n            \"Replace this `void` type with an allowed type, or keep `void` only in a valid return position.\",\n        )\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone, Deserialize)]\npub struct NoInvalidVoidType(Box<NoInvalidVoidTypeConfig>);","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/typescript/no_invalid_void_type.rs#L35-L71","documentation":"The most permissive single-position variant of the no-invalid-void-type message (no_invalid_void_type.rs:54-60): it lists return types, generic type arguments, and `this` parameter types as the allowed positions, and fires for `void` used anywhere else under a config that permits all three.","triggerScenarios":"`let v: void`, `obj.prop: void`, `(x: void) => x` - any non-return, non-generic, non-this usage under the fully permissive configuration.","commonSituations":"Large codebases where different teams use different allowances; central lint config permissive on generics and this-params while individual annotations still misuse `void`.","solutions":["Replace the offending `void` with `undefined`","Restructure the code so `void` lands in a return type","Align the annotation with one of the allowed positions or relax the rule config deliberately"],"exampleFix":"// before\ninterface State {\n  loaded: void;\n}\n\n// after\ninterface State {\n  loaded: undefined;\n}","handlingStrategy":"validation","validationCode":"npx oxlint --deny-warnings .","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Audit interfaces and type aliases for `void` members; they should be `undefined`","Keep a one-line rule-of-thumb in the style guide: `void` only on returns, `this` params, and allow-listed generics","Run the linter in the editor so violations are fixed at typing time"],"tags":["typescript","lint","void","type-annotation"],"backgroundTag":"invalid-void-type","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}