fix(typescript): preserve necessary parens for TSOptionalType (#5056)

This commit is contained in:
Ika authored and GitHub committed 2018-09-06 09:04:37 +08:00
1 parent ff4ef426e6
commit 461e6035c1
3 files changed
+10 -1

No files matched your search

+2 -1
View File
@@ -317,7 +317,8 @@ function needsParens(path, options) {
parent.type === "TSTypeReference") &&
(node.typeAnnotation.type === "TSTypeAnnotation" &&
node.typeAnnotation.typeAnnotation.type !== "TSFunctionType" &&
grandParent.type !== "TSTypeOperator")
grandParent.type !== "TSTypeOperator" &&
grandParent.type !== "TSOptionalType")
) {
return false;
}
@@ -1,5 +1,12 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`complex.ts - typescript-verify 1`] = `
type T = [("a" | "b")?];
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
type T = [("a" | "b")?];
`;
exports[`simple.ts - typescript-verify 1`] = `
type X = [number, string?];
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -0,0 +1 @@
type T = [("a" | "b")?];