fix(typescript): preserve necessary parens for TSOptionalType (#5056)
This commit is contained in:
3 files changed
+10
-1
No files matched your search
@@ -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")?];
|
||||
Reference in new issue
Block a user