Skip to content
Open
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
1 change: 1 addition & 0 deletions src/generation/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3279,6 +3279,7 @@ fn gen_template_literal<'a>(quasis: Vec<Node<'a>>, exprs: Vec<Node<'a>>, 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()),
Expand Down
23 changes: 23 additions & 0 deletions tests/specs/types/TplLitType/TplLitType_All.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
~~ lineWidth: 80, indentWidth: 2 ~~
== should format a template literal type ==
type Test<T> = `${string & keyof T}Changed`;

[expect]
type Test<T> = `${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}`;
Loading