{"record":{"id":"57a5da39021d47c6","repo":"oxc-project/oxc","slug":"missing-return-type-on-function","errorCode":null,"errorMessage":"Missing return type on function.","messagePattern":"Missing return type on function\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/typescript/explicit_function_return_type.rs","lineNumber":143,"sourceCode":"    /// var arrowFn = (): string => 'test'\n    ///\n    /// class Test {\n    ///     // No return value should be expected (void)\n    ///     method(): void {\n    ///         return\n    ///     }\n    /// }\n    /// ```\n    ExplicitFunctionReturnType,\n    typescript,\n    restriction,\n    config = ExplicitFunctionReturnTypeConfig,\n    version = \"0.4.4\",\n    short_description = \"This rule enforces that functions have an explicit return type annotation.\",\n);\n\nfn explicit_function_return_type_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Missing return type on function.\")\n        // TODO: actually provide a helpful message.\n        .with_help(\"Require explicit return types on functions and class methods.\")\n        .with_label(span)\n}\n\nimpl Rule for ExplicitFunctionReturnType {\n    fn from_configuration(value: serde_json::Value) -> Result<Self, serde_json::error::Error> {\n        DefaultRuleConfig::<Self>::from_value(value).map(DefaultRuleConfig::into_inner)\n    }\n\n    fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) {\n        match node.kind() {\n            AstKind::Function(func) => {\n                if !func.is_declaration() && !func.is_expression() {\n                    return;\n                }\n\n                if func.return_type.is_some() || is_constructor_or_setter(node, ctx) {","sourceCodeStart":125,"sourceCodeEnd":161,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/typescript/explicit_function_return_type.rs#L125-L161","documentation":"typescript/explicit-function-return-type reports function-like nodes whose return_type is None. Defaults: allowTypedFunctionExpressions, allowHigherOrderFunctions, and allowDirectConstAssertionInArrowFunctions are true, while allowExpressions and allowIIFEs are false, so unannotated function declarations, methods, and immediately-invoked functions are the main targets. It forces the author to state the output contract explicitly.","triggerScenarios":"`function f() {}`, `const f = () => 1;`, class methods without return annotations, or `(function () {})()` with allowIIFEs left false; the node is only exempt if it matches one of the allow* conditions (e.g. a typed function expression or a directly returned arrow with `as const`).","commonSituations":"Turning the rule on mid-project and getting hundreds of reports; arrow functions assigned to untyped consts; callbacks flagged because allowExpressions is false; teams wanting return types only on public APIs (explicit-module-boundary-types) rather than everywhere.","solutions":["Add the return type: `function f(): void {}`, `const f = (): number => 1`, `method(): string { ... }`","Set \"allowExpressions\": true to exempt function expressions passed as arguments or assigned to variables","Set \"allowIIFEs\": true if immediately-invoked functions should be exempt","If the policy is too strict, replace this rule with typescript/explicit-module-boundary-types which only checks the exported surface"],"exampleFix":"// before\nfunction add(a: number, b: number) {\n  return a + b;\n}\n\n// after\nfunction add(a: number, b: number): number {\n  return a + b;\n}","handlingStrategy":"validation","validationCode":"// .oxlintrc.json — scope the rule to what the team actually wants\n{\n  \"rules\": {\n    \"typescript/explicit-function-return-type\": [\n      \"warn\",\n      {\n        \"allowExpressions\": true,\n        \"allowIIFEs\": true,\n        \"allowTypedFunctionExpressions\": true,\n        \"allowHigherOrderFunctions\": true,\n        \"allowDirectConstAssertionInArrowFunctions\": true\n      }\n    ]\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Turn the rule on with allowExpressions/allowIIFEs first, then tighten incrementally to keep the report count actionable","Enable noImplicitAny so the compiler pushes toward annotations in parallel with the linter","Require return types in code review for exported functions even if the rule only warns"],"tags":["typescript","lint","annotations","return-type","oxlint"],"backgroundTag":"missing-return-type-annotation","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"}