diff --git a/packages/eslint-plugin/src/rules/array-type.ts b/packages/eslint-plugin/src/rules/array-type.ts index 92040d8106a..f353207e7d5 100644 --- a/packages/eslint-plugin/src/rules/array-type.ts +++ b/packages/eslint-plugin/src/rules/array-type.ts @@ -252,8 +252,7 @@ export default util.createRule({ } const type = typeParams[0]; - const typeParens = - !util.isParenthesized(type, sourceCode) && typeNeedsParentheses(type); + const typeParens = typeNeedsParentheses(type); const parentParens = readonlyPrefix && node.parent?.type === AST_NODE_TYPES.TSArrayType && diff --git a/packages/eslint-plugin/tests/rules/array-type.test.ts b/packages/eslint-plugin/tests/rules/array-type.test.ts index c32da51cc08..04ab47d0b8a 100644 --- a/packages/eslint-plugin/tests/rules/array-type.test.ts +++ b/packages/eslint-plugin/tests/rules/array-type.test.ts @@ -1982,6 +1982,61 @@ class Foo extends Bar implements Baz { } `, ); + testOutput( + 'array', + ` +interface WorkingArray { + outerProperty: Array< + { innerPropertyOne: string } & { innerPropertyTwo: string } + >; +} + +interface BrokenArray { + outerProperty: Array< + ({ innerPropertyOne: string } & { innerPropertyTwo: string }) + >; +} + `, + ` +interface WorkingArray { + outerProperty: ({ innerPropertyOne: string } & { innerPropertyTwo: string })[]; +} + +interface BrokenArray { + outerProperty: ({ innerPropertyOne: string } & { innerPropertyTwo: string })[]; +} + `, + ); + testOutput( + 'array', + ` +type WorkingArray = { + outerProperty: Array< + { innerPropertyOne: string } & { innerPropertyTwo: string } + >; +} + +type BrokenArray = { + outerProperty: Array< + ({ innerPropertyOne: string } & { innerPropertyTwo: string }) + >; +} + `, + ` +type WorkingArray = { + outerProperty: ({ innerPropertyOne: string } & { innerPropertyTwo: string })[]; +} + +type BrokenArray = { + outerProperty: ({ innerPropertyOne: string } & { innerPropertyTwo: string })[]; +} + `, + ); + testOutput( + 'array', + 'const a: Array<(string|number)>;', + 'const a: (string|number)[];', + ); testOutput( 'array-simple', 'let xx: Array> = [[1, 2], [3]];',