diff --git a/src/language-js/needs-parens.js b/src/language-js/needs-parens.js index 402fee36..c991b6b1 100644 --- a/src/language-js/needs-parens.js +++ b/src/language-js/needs-parens.js @@ -339,7 +339,6 @@ function needsParens(path, options) { parent.type === "GenericTypeAnnotation" || parent.type === "TSTypeReference") && (node.typeAnnotation.type === "TSTypeAnnotation" && - node.typeAnnotation.typeAnnotation.type !== "TSFunctionType" && grandParent.type !== "TSTypeOperator" && grandParent.type !== "TSOptionalType") ) { diff --git a/tests/typescript/conformance/types/functions/TSFunctionTypeNoUnnecessaryParentheses.ts b/tests/typescript/conformance/types/functions/TSFunctionTypeNoUnnecessaryParentheses.ts new file mode 100644 index 00000000..9de88dbf --- /dev/null +++ b/tests/typescript/conformance/types/functions/TSFunctionTypeNoUnnecessaryParentheses.ts @@ -0,0 +1,3 @@ +class Foo { + bar: (() => boolean); +} \ No newline at end of file diff --git a/tests/typescript/conformance/types/functions/__snapshots__/jsfmt.spec.js.snap b/tests/typescript/conformance/types/functions/__snapshots__/jsfmt.spec.js.snap index c420d25b..aec0463d 100644 --- a/tests/typescript/conformance/types/functions/__snapshots__/jsfmt.spec.js.snap +++ b/tests/typescript/conformance/types/functions/__snapshots__/jsfmt.spec.js.snap @@ -1,5 +1,22 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`TSFunctionTypeNoUnnecessaryParentheses.ts 1`] = ` +====================================options===================================== +parsers: ["typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +class Foo { + bar: (() => boolean); +} +=====================================output===================================== +class Foo { + bar: () => boolean; +} + +================================================================================ +`; + exports[`functionImplementationErrors.ts 1`] = ` ====================================options===================================== parsers: ["typescript"]