fix(typescript): preserve necessary parens for TSOptionalType (#5056)
parent
ff4ef426e6
commit
461e6035c1
|
@ -317,7 +317,8 @@ function needsParens(path, options) {
|
||||||
parent.type === "TSTypeReference") &&
|
parent.type === "TSTypeReference") &&
|
||||||
(node.typeAnnotation.type === "TSTypeAnnotation" &&
|
(node.typeAnnotation.type === "TSTypeAnnotation" &&
|
||||||
node.typeAnnotation.typeAnnotation.type !== "TSFunctionType" &&
|
node.typeAnnotation.typeAnnotation.type !== "TSFunctionType" &&
|
||||||
grandParent.type !== "TSTypeOperator")
|
grandParent.type !== "TSTypeOperator" &&
|
||||||
|
grandParent.type !== "TSOptionalType")
|
||||||
) {
|
) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,12 @@
|
||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
// 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`] = `
|
exports[`simple.ts - typescript-verify 1`] = `
|
||||||
type X = [number, string?];
|
type X = [number, string?];
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
type T = [("a" | "b")?];
|
Loading…
Reference in New Issue