Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion crates/oxc_isolated_declarations/src/return_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,13 @@ impl<'a> FunctionReturnType<'a> {
}
}

//
// If there are multiple return statements, which means there must be a union with `undefined`
if visitor.return_statement_count > 1 {
// Here is a union type, if the return type is a function type, we need to wrap it in parentheses
if matches!(expr_type, TSType::TSFunctionType(_)) {
expr_type = transformer.ast.ts_type_parenthesized_type(SPAN, expr_type);
}

let types = transformer
.ast
.vec_from_iter([expr_type, transformer.ast.ts_type_undefined_keyword(SPAN)]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,11 @@ function quux() {
return `${''}`
}
// Inferred type is string

function returnFunctionOrNothing() {
if (process.env.NODE_ENV === 'development') {
return
}

return () => 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ declare function bar(): number | undefined;
declare function baz();
declare function qux(): string;
declare function quux(): string;
declare function returnFunctionOrNothing(): (() => number) | undefined;


==================== Errors ====================
Expand Down