Skip to content

Commit

Permalink
fix(js_formatter): remove useless parens around infer type (biomejs#3693
Browse files Browse the repository at this point in the history
)
  • Loading branch information
Conaclos authored Aug 21, 2024
1 parent b690ee3 commit 14c7d97
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ our [guidelines for writing a good changelog entry](https://github.com/biomejs/b

#### Bug fixes

- Keep the parentheses around `infer` declarations in type unions and type intersections ([#3419](https://github.com/biomejs/biome/issues/3419)). Contributed by @Conaclos
- Keep the parentheses around `infer ... extends` declarations in type unions and type intersections ([#3419](https://github.com/biomejs/biome/issues/3419)). Contributed by @Conaclos

- Keep parentheses around a `yield` expression inside a type assertion.

Expand Down
16 changes: 10 additions & 6 deletions crates/biome_js_formatter/src/ts/types/infer_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,33 +38,37 @@ mod tests {
#[test]
fn needs_parentheses() {
assert_needs_parentheses!(
"type A = T extends (infer string)[] ? string : never",
"type A<T> = T extends (infer string)[] ? string : never",
TsInferType
);
assert_needs_parentheses!(
"type A = T extends unique (infer string) ? string : never",
"type A<T> = T extends unique (infer string) ? string : never",
TsInferType
);

assert_not_needs_parentheses!(
"type A = T extends [number, ...infer string] ? string : never",
"type A<T> = T extends [number, ...infer string] ? string : never",
TsInferType
);
assert_needs_parentheses!(
"type A = T extends [(infer string)?] ? string : never",
TsInferType
);
assert_needs_parentheses!(
"type A = T extends [(infer string) | undefined] ? string : never",
"type A<T> = [T] extends [(infer S extends string) | undefined] ? S : T",
TsInferType
);

assert_needs_parentheses!(
"type A = T extends (infer string)[a] ? string : never",
"type A<T> = T extends (infer string)[a] ? string : never",
TsInferType
);
assert_not_needs_parentheses!(
"type A = T extends a[(infer string)] ? string : never",
"type A<T> = T extends a[(infer string)] ? string : never",
TsInferType
);
assert_not_needs_parentheses!(
"type A = T extends () => infer R | B ? R : never",
TsInferType
);
}
Expand Down
2 changes: 1 addition & 1 deletion crates/biome_js_syntax/src/parentheses/tstype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl NeedsParentheses for TsInferType {
match parent.kind() {
JsSyntaxKind::TS_REST_TUPLE_TYPE_ELEMENT => false,
JsSyntaxKind::TS_INTERSECTION_TYPE_ELEMENT_LIST
| JsSyntaxKind::TS_UNION_TYPE_VARIANT_LIST => true,
| JsSyntaxKind::TS_UNION_TYPE_VARIANT_LIST => self.constraint().is_some(),
_ => operator_type_or_higher_needs_parens(self.syntax(), parent),
}
}
Expand Down

0 comments on commit 14c7d97

Please sign in to comment.