Skip to content

Commit 30979ed

Browse files
flurmboduailibe
authored andcommitted
typescript: remove unneeded parentheses around type annotation (#5724)
* Remove unnecessary parentheses from annotations * add test for ts parentheses bug
1 parent 1473010 commit 30979ed

3 files changed

Lines changed: 20 additions & 1 deletion

File tree

src/language-js/needs-parens.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,6 @@ function needsParens(path, options) {
339339
parent.type === "GenericTypeAnnotation" ||
340340
parent.type === "TSTypeReference") &&
341341
(node.typeAnnotation.type === "TSTypeAnnotation" &&
342-
node.typeAnnotation.typeAnnotation.type !== "TSFunctionType" &&
343342
grandParent.type !== "TSTypeOperator" &&
344343
grandParent.type !== "TSOptionalType")
345344
) {
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class Foo {
2+
bar: (() => boolean);
3+
}

tests/typescript/conformance/types/functions/__snapshots__/jsfmt.spec.js.snap

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3+
exports[`TSFunctionTypeNoUnnecessaryParentheses.ts 1`] = `
4+
====================================options=====================================
5+
parsers: ["typescript"]
6+
printWidth: 80
7+
| printWidth
8+
=====================================input======================================
9+
class Foo {
10+
bar: (() => boolean);
11+
}
12+
=====================================output=====================================
13+
class Foo {
14+
bar: () => boolean;
15+
}
16+
17+
================================================================================
18+
`;
19+
320
exports[`functionImplementationErrors.ts 1`] = `
421
====================================options=====================================
522
parsers: ["typescript"]

0 commit comments

Comments
 (0)