Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(js_formatter): remove useless parens around infer type #3693

Merged
merged 1 commit into from
Aug 21, 2024
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
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
Loading