TypeScript: Fix incorrectly removes double parentheses around types (#6604)
parent
affa24ce76
commit
02cbd15ec2
|
@ -742,6 +742,29 @@ Previously, the flag was not applied on html attributes.
|
||||||
<div class='a-class-name'></div>
|
<div class='a-class-name'></div>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### TypeScript: Fix incorrectly removes double parentheses around types ([#6604] by [@sosukesuzuki])
|
||||||
|
|
||||||
|
<!-- prettier-ignore -->
|
||||||
|
```ts
|
||||||
|
// Input
|
||||||
|
type A = 0 extends ((1 extends 2 ? 3 : 4)) ? 5 : 6;
|
||||||
|
type B = ((0 extends 1 ? 2 : 3)) extends 4 ? 5 : 6:
|
||||||
|
type C = ((number | string))["toString"];
|
||||||
|
type D = ((keyof T1))["foo"];
|
||||||
|
|
||||||
|
// Prettier (stable)
|
||||||
|
type A = 0 extends 1 extends 2 ? 3 : 4 ? 5 : 6;
|
||||||
|
type B = 0 extends 1 ? 2 : 3 extends 4 ? 5 : 6;
|
||||||
|
type C = number | string["toString"];
|
||||||
|
type D = keyof T1["foo"];
|
||||||
|
|
||||||
|
// Prettier (master)
|
||||||
|
type A = 0 extends (1 extends 2 ? 3 : 4) ? 5 : 6;
|
||||||
|
type B = (0 extends 1 ? 2 : 3) extends 4 ? 5 : 6;
|
||||||
|
type C = (number | string)["toString"];
|
||||||
|
type D = (keyof T1)["foo"];
|
||||||
|
```
|
||||||
|
|
||||||
[#5910]: https://github.com/prettier/prettier/pull/5910
|
[#5910]: https://github.com/prettier/prettier/pull/5910
|
||||||
[#6033]: https://github.com/prettier/prettier/pull/6033
|
[#6033]: https://github.com/prettier/prettier/pull/6033
|
||||||
[#6186]: https://github.com/prettier/prettier/pull/6186
|
[#6186]: https://github.com/prettier/prettier/pull/6186
|
||||||
|
@ -768,6 +791,7 @@ Previously, the flag was not applied on html attributes.
|
||||||
[#6514]: https://github.com/prettier/prettier/pull/6514
|
[#6514]: https://github.com/prettier/prettier/pull/6514
|
||||||
[#6467]: https://github.com/prettier/prettier/pull/6467
|
[#6467]: https://github.com/prettier/prettier/pull/6467
|
||||||
[#6377]: https://github.com/prettier/prettier/pull/6377
|
[#6377]: https://github.com/prettier/prettier/pull/6377
|
||||||
|
[#6604]: https://github.com/prettier/prettier/pull/6604
|
||||||
[@brainkim]: https://github.com/brainkim
|
[@brainkim]: https://github.com/brainkim
|
||||||
[@duailibe]: https://github.com/duailibe
|
[@duailibe]: https://github.com/duailibe
|
||||||
[@gavinjoyce]: https://github.com/gavinjoyce
|
[@gavinjoyce]: https://github.com/gavinjoyce
|
||||||
|
|
|
@ -411,7 +411,11 @@ function needsParens(path, options) {
|
||||||
// Delegate to inner TSParenthesizedType
|
// Delegate to inner TSParenthesizedType
|
||||||
if (
|
if (
|
||||||
node.typeAnnotation.type === "TSParenthesizedType" &&
|
node.typeAnnotation.type === "TSParenthesizedType" &&
|
||||||
parent.type !== "TSArrayType"
|
parent.type !== "TSArrayType" &&
|
||||||
|
parent.type !== "TSIndexedAccessType" &&
|
||||||
|
parent.type !== "TSConditionalType" &&
|
||||||
|
parent.type !== "TSIntersectionType" &&
|
||||||
|
parent.type !== "TSUnionType"
|
||||||
) {
|
) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,15 @@ type TypeName<T> =
|
||||||
T extends Function ? "function" :
|
T extends Function ? "function" :
|
||||||
"object";
|
"object";
|
||||||
|
|
||||||
|
type Type01 = 0 extends (1 extends 2 ? 3 : 4) ? 5 : 6;
|
||||||
|
type Type02 = 0 extends ((1 extends 2 ? 3 : 4)) ? 5 : 6;
|
||||||
|
type Type03 = 0 extends (((1 extends 2 ? 3 : 4))) ? 5 : 6;
|
||||||
|
type Type04 = 0 extends ((((1 extends 2 ? 3 : 4)))) ? 5 : 6;
|
||||||
|
type Type05 = (0 extends 1 ? 2 : 3) extends 4 ? 5 : 6;
|
||||||
|
type Type06 = ((0 extends 1 ? 2 : 3)) extends 4 ? 5 : 6;
|
||||||
|
type Type07 = (((0 extends 1 ? 2 : 3))) extends 4 ? 5 : 6;
|
||||||
|
type Type08 = ((((0 extends 1 ? 2 : 3)))) extends 4 ? 5 : 6;
|
||||||
|
|
||||||
=====================================output=====================================
|
=====================================output=====================================
|
||||||
export type DeepReadonly<T> = T extends any[]
|
export type DeepReadonly<T> = T extends any[]
|
||||||
? DeepReadonlyArray<T[number]>
|
? DeepReadonlyArray<T[number]>
|
||||||
|
@ -53,6 +62,15 @@ type TypeName<T> = T extends string
|
||||||
? "function"
|
? "function"
|
||||||
: "object";
|
: "object";
|
||||||
|
|
||||||
|
type Type01 = 0 extends (1 extends 2 ? 3 : 4) ? 5 : 6;
|
||||||
|
type Type02 = 0 extends (1 extends 2 ? 3 : 4) ? 5 : 6;
|
||||||
|
type Type03 = 0 extends (1 extends 2 ? 3 : 4) ? 5 : 6;
|
||||||
|
type Type04 = 0 extends (1 extends 2 ? 3 : 4) ? 5 : 6;
|
||||||
|
type Type05 = (0 extends 1 ? 2 : 3) extends 4 ? 5 : 6;
|
||||||
|
type Type06 = (0 extends 1 ? 2 : 3) extends 4 ? 5 : 6;
|
||||||
|
type Type07 = (0 extends 1 ? 2 : 3) extends 4 ? 5 : 6;
|
||||||
|
type Type08 = (0 extends 1 ? 2 : 3) extends 4 ? 5 : 6;
|
||||||
|
|
||||||
================================================================================
|
================================================================================
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
|
|
@ -15,3 +15,12 @@ type TypeName<T> =
|
||||||
T extends undefined ? "undefined" :
|
T extends undefined ? "undefined" :
|
||||||
T extends Function ? "function" :
|
T extends Function ? "function" :
|
||||||
"object";
|
"object";
|
||||||
|
|
||||||
|
type Type01 = 0 extends (1 extends 2 ? 3 : 4) ? 5 : 6;
|
||||||
|
type Type02 = 0 extends ((1 extends 2 ? 3 : 4)) ? 5 : 6;
|
||||||
|
type Type03 = 0 extends (((1 extends 2 ? 3 : 4))) ? 5 : 6;
|
||||||
|
type Type04 = 0 extends ((((1 extends 2 ? 3 : 4)))) ? 5 : 6;
|
||||||
|
type Type05 = (0 extends 1 ? 2 : 3) extends 4 ? 5 : 6;
|
||||||
|
type Type06 = ((0 extends 1 ? 2 : 3)) extends 4 ? 5 : 6;
|
||||||
|
type Type07 = (((0 extends 1 ? 2 : 3))) extends 4 ? 5 : 6;
|
||||||
|
type Type08 = ((((0 extends 1 ? 2 : 3)))) extends 4 ? 5 : 6;
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`intersection-parens.ts 1`] = `
|
||||||
|
====================================options=====================================
|
||||||
|
parsers: ["typescript"]
|
||||||
|
printWidth: 80
|
||||||
|
| printWidth
|
||||||
|
=====================================input======================================
|
||||||
|
type A = (number | string) & boolean;
|
||||||
|
type B = ((number | string)) & boolean;
|
||||||
|
type C = (((number | string))) & boolean;
|
||||||
|
type D = ((((number | string)))) & boolean;
|
||||||
|
|
||||||
|
=====================================output=====================================
|
||||||
|
type A = (number | string) & boolean;
|
||||||
|
type B = (number | string) & boolean;
|
||||||
|
type C = (number | string) & boolean;
|
||||||
|
type D = (number | string) & boolean;
|
||||||
|
|
||||||
|
================================================================================
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`intersection-parens.ts 2`] = `
|
||||||
|
====================================options=====================================
|
||||||
|
parsers: ["typescript"]
|
||||||
|
printWidth: 80
|
||||||
|
semi: false
|
||||||
|
| printWidth
|
||||||
|
=====================================input======================================
|
||||||
|
type A = (number | string) & boolean;
|
||||||
|
type B = ((number | string)) & boolean;
|
||||||
|
type C = (((number | string))) & boolean;
|
||||||
|
type D = ((((number | string)))) & boolean;
|
||||||
|
|
||||||
|
=====================================output=====================================
|
||||||
|
type A = (number | string) & boolean
|
||||||
|
type B = (number | string) & boolean
|
||||||
|
type C = (number | string) & boolean
|
||||||
|
type D = (number | string) & boolean
|
||||||
|
|
||||||
|
================================================================================
|
||||||
|
`;
|
|
@ -0,0 +1,4 @@
|
||||||
|
type A = (number | string) & boolean;
|
||||||
|
type B = ((number | string)) & boolean;
|
||||||
|
type C = (((number | string))) & boolean;
|
||||||
|
type D = ((((number | string)))) & boolean;
|
|
@ -0,0 +1,2 @@
|
||||||
|
run_spec(__dirname, ["typescript"]);
|
||||||
|
run_spec(__dirname, ["typescript"], { semi: false });
|
|
@ -12,7 +12,10 @@ type C = keyof T | U;
|
||||||
type D = keyof X & Y;
|
type D = keyof X & Y;
|
||||||
type E = (keyof T)[];
|
type E = (keyof T)[];
|
||||||
type F = ((keyof T))[];
|
type F = ((keyof T))[];
|
||||||
|
type G = (keyof T1)["foo"];
|
||||||
|
type H = ((keyof T1))["foo"];
|
||||||
|
type I = (((keyof T1)))["foo"];
|
||||||
|
type J = ((((keyof T1))))["foo"];
|
||||||
|
|
||||||
=====================================output=====================================
|
=====================================output=====================================
|
||||||
type A = keyof (T | U);
|
type A = keyof (T | U);
|
||||||
|
@ -21,6 +24,10 @@ type C = keyof T | U;
|
||||||
type D = keyof X & Y;
|
type D = keyof X & Y;
|
||||||
type E = (keyof T)[];
|
type E = (keyof T)[];
|
||||||
type F = (keyof T)[];
|
type F = (keyof T)[];
|
||||||
|
type G = (keyof T1)["foo"];
|
||||||
|
type H = (keyof T1)["foo"];
|
||||||
|
type I = (keyof T1)["foo"];
|
||||||
|
type J = (keyof T1)["foo"];
|
||||||
|
|
||||||
================================================================================
|
================================================================================
|
||||||
`;
|
`;
|
||||||
|
|
|
@ -4,4 +4,7 @@ type C = keyof T | U;
|
||||||
type D = keyof X & Y;
|
type D = keyof X & Y;
|
||||||
type E = (keyof T)[];
|
type E = (keyof T)[];
|
||||||
type F = ((keyof T))[];
|
type F = ((keyof T))[];
|
||||||
|
type G = (keyof T1)["foo"];
|
||||||
|
type H = ((keyof T1))["foo"];
|
||||||
|
type I = (((keyof T1)))["foo"];
|
||||||
|
type J = ((((keyof T1))))["foo"];
|
||||||
|
|
|
@ -39,6 +39,15 @@ type window = Window & {
|
||||||
__REDUX_DEVTOOLS_EXTENSION_COMPOSE__: Function;
|
__REDUX_DEVTOOLS_EXTENSION_COMPOSE__: Function;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type T1 = (number | string)["toString"];
|
||||||
|
type T2 = ((number | string))["toString"];
|
||||||
|
type T3 = (((number | string)))["toString"];
|
||||||
|
type T4 = ((((number | string))))["toString"];
|
||||||
|
type T5 = number | ((arg: any) => void);
|
||||||
|
type T6 = number | (((arg: any) => void));
|
||||||
|
type T7 = number | ((((arg: any) => void)));
|
||||||
|
type T8 = number | (((((arg: any) => void))));
|
||||||
|
|
||||||
=====================================output=====================================
|
=====================================output=====================================
|
||||||
interface RelayProps {
|
interface RelayProps {
|
||||||
articles: a | null;
|
articles: a | null;
|
||||||
|
@ -73,6 +82,15 @@ type window = Window & {
|
||||||
__REDUX_DEVTOOLS_EXTENSION_COMPOSE__: Function;
|
__REDUX_DEVTOOLS_EXTENSION_COMPOSE__: Function;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type T1 = (number | string)["toString"];
|
||||||
|
type T2 = (number | string)["toString"];
|
||||||
|
type T3 = (number | string)["toString"];
|
||||||
|
type T4 = (number | string)["toString"];
|
||||||
|
type T5 = number | ((arg: any) => void);
|
||||||
|
type T6 = number | ((arg: any) => void);
|
||||||
|
type T7 = number | ((arg: any) => void);
|
||||||
|
type T8 = number | ((arg: any) => void);
|
||||||
|
|
||||||
================================================================================
|
================================================================================
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
|
|
@ -30,3 +30,12 @@ type UploadState<E, EM, D>
|
||||||
type window = Window & {
|
type window = Window & {
|
||||||
__REDUX_DEVTOOLS_EXTENSION_COMPOSE__: Function;
|
__REDUX_DEVTOOLS_EXTENSION_COMPOSE__: Function;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type T1 = (number | string)["toString"];
|
||||||
|
type T2 = ((number | string))["toString"];
|
||||||
|
type T3 = (((number | string)))["toString"];
|
||||||
|
type T4 = ((((number | string))))["toString"];
|
||||||
|
type T5 = number | ((arg: any) => void);
|
||||||
|
type T6 = number | (((arg: any) => void));
|
||||||
|
type T7 = number | ((((arg: any) => void)));
|
||||||
|
type T8 = number | (((((arg: any) => void))));
|
||||||
|
|
Loading…
Reference in New Issue