typescript: remove unneeded parentheses around type annotation (#5724)

* Remove unnecessary parentheses from annotations

* add test for ts parentheses bug
master
Phil 2019-01-07 06:19:41 -06:00 committed by Lucas Duailibe
parent 14730106db
commit 30979ed104
3 changed files with 20 additions and 1 deletions

View File

@ -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")
) {

View File

@ -0,0 +1,3 @@
class Foo {
bar: (() => boolean);
}

View File

@ -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"]