mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 04:08:41 +00:00
fix(isolated-declarations): wrap TSFunctionType in parentheses if it is inside the TSUnionType (#5963)
This commit is contained in:
parent
eed9ac7c46
commit
6a9e71da46
3 changed files with 15 additions and 1 deletions
|
|
@ -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)]);
|
||||
|
|
|
|||
|
|
@ -30,3 +30,11 @@ function quux() {
|
|||
return `${''}`
|
||||
}
|
||||
// Inferred type is string
|
||||
|
||||
function returnFunctionOrNothing() {
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
return
|
||||
}
|
||||
|
||||
return () => 0;
|
||||
}
|
||||
|
|
@ -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 ====================
|
||||
|
|
|
|||
Loading…
Reference in a new issue