diff --git a/src/generation/generate.rs b/src/generation/generate.rs index 7fb3a332..119454db 100644 --- a/src/generation/generate.rs +++ b/src/generation/generate.rs @@ -3279,6 +3279,7 @@ fn gen_template_literal<'a>(quasis: Vec>, exprs: Vec>, context Node::OptChainExpr(expr) => get_possible_surround_newlines(expr.base.as_node()), Node::CondExpr(_) => true, Node::BinExpr(_) => true, + Node::TsUnionType(_) | Node::TsIntersectionType(_) => true, Node::MemberExpr(expr) => !keep_member_expr_on_one_line(expr), Node::CallExpr(expr) => !keep_call_expr_on_one_line(expr.into()), Node::OptCall(expr) => !keep_call_expr_on_one_line(expr.into()), diff --git a/tests/specs/types/TplLitType/TplLitType_All.txt b/tests/specs/types/TplLitType/TplLitType_All.txt index 4a9f5632..52145bd3 100644 --- a/tests/specs/types/TplLitType/TplLitType_All.txt +++ b/tests/specs/types/TplLitType/TplLitType_All.txt @@ -1,5 +1,28 @@ +~~ lineWidth: 80, indentWidth: 2 ~~ == should format a template literal type == type Test = `${string & keyof T}Changed`; [expect] type Test = `${string & keyof T}Changed`; + +== should keep union template literal type expression on one line when it fits == +type Foo = `${typeof X | typeof Y}__${typeof Z | typeof W}`; + +[expect] +type Foo = `${typeof X | typeof Y}__${typeof Z | typeof W}`; + +== should surround union template literal type expression with newlines when too long == +export type SortSelector = `${typeof Descending | typeof Ascending}${SortItems}`; + +[expect] +export type SortSelector = `${ + typeof Descending | typeof Ascending +}${SortItems}`; + +== should surround intersection template literal type expression with newlines when too long == +export type IntersectionTpl = `${typeof Descending & typeof Ascending}${SortItems}`; + +[expect] +export type IntersectionTpl = `${ + typeof Descending & typeof Ascending +}${SortItems}`;