{"record":{"id":"1781f32da7bedb8a","repo":"oxc-project/oxc","slug":"do-not-use-void-as-a-type-argument-for-generic","errorCode":null,"errorMessage":"Do not use `void` as a type argument for `{generic}`.","messagePattern":"Do not use `void` as a type argument for `(.+?)`\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/typescript/no_invalid_void_type.rs","lineNumber":21,"sourceCode":"    ast::{\n        ClassElement, Declaration, ExportDefaultDeclarationKind, Function, FunctionType,\n        MethodDefinition, ModuleDeclaration, Statement, TSType, TSUnionType,\n    },\n};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::{GetSpan, Span};\nuse 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.\",","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/typescript/no_invalid_void_type.rs#L3-L39","documentation":"Message from no-invalid-void-type that interpolates the generic name: using `void` as a type argument (for example `Array<void>`) is only allowed for generics listed in allowInGenericTypeArguments (a boolean or a list such as Promise). When the generic in use is not permitted, this diagnostic fires with its name filled into the warn at no_invalid_void_type.rs:21-26.","triggerScenarios":"`let x: Array<void>`, `Foo<void>` where Foo is not in allowInGenericTypeArguments; configuring the option as an explicit list that omits the generic you actually use.","commonSituations":"Teams restricting `void` to return positions by narrowing the allow list; debates over Promise<void> versus Promise<undefined> in callback-heavy APIs.","solutions":["Use `undefined` as the type argument (`Array<undefined>`)","Add the generic name to allowInGenericTypeArguments (for example \"Promise\")","Set allowInGenericTypeArguments: true to permit all generics"],"exampleFix":"// before\nconst steps: Array<void> = [];\n\n// after\nconst steps: Array<undefined> = [];","handlingStrategy":"validation","validationCode":"{\n  \"rules\": {\n    \"typescript/no-invalid-void-type\": [\"error\", { \"allowInGenericTypeArguments\": [\"Promise\"] }]\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use `undefined` whenever a slot means 'the undefined value' and reserve `void` for ignored returns","Decide the team's Promise<void> policy once and encode it in allowInGenericTypeArguments","Grep for `Array<void>` and `Map<..., void>` when adopting the rule"],"tags":["typescript","lint","void","generics"],"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"}