{"record":{"id":"8bc692725a583d59","repo":"oxc-project/oxc","slug":"use-void-only-as-a-return-type","errorCode":null,"errorMessage":"Use `void` only as a return type.","messagePattern":"Use `void` only as a return type\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/typescript/no_invalid_void_type.rs","lineNumber":29,"sourceCode":"use schemars::JsonSchema;\nuse serde::{Deserialize, Serialize};\n\nuse crate::{\n    AstNode,\n    context::{ContextHost, LintContext},\n    rule::{DefaultRuleConfig, Rule},\n};\n\nfn invalid_void_for_generic_diagnostic(span: Span, generic: &str) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\"Do not use `void` as a type argument for `{generic}`.\"))\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_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Use `void` only as a return type.\")\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_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.\",","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/typescript/no_invalid_void_type.rs#L11-L47","documentation":"Base message of no-invalid-void-type: `void` means 'this function's return value is ignored', so using it in any position other than a return type is flagged. This variant (no_invalid_void_type.rs:30-36) is the one emitted when the config permits no other allowances, such as generic type arguments.","triggerScenarios":"`let x: void`, a parameter annotated `void`, `void` as an object property type, with allowInGenericTypeArguments disabled so no generic slot is permitted either.","commonSituations":"Developers using `void` where they mean `undefined`; config tightened to ban generics, making previously tolerated usages fail.","solutions":["Replace the annotation with `undefined`","Restructure so the value is a function return (where `void` is legal)","Re-enable the allowances you need in the rule config"],"exampleFix":"// before\nlet result: void;\n\n// after\nlet result: undefined;","handlingStrategy":"validation","validationCode":"npx oxlint --deny-warnings .","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Teach the distinction: `void` = ignored return, `undefined` = the value undefined","Annotate variables and properties as `undefined | T`, never `void | T`","Add the rule to the editor plugin so mistakes surface while typing"],"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-14T00:17:10.932Z"}