diff --git a/src/rules/arrayTypeRule.ts b/src/rules/arrayTypeRule.ts index dcc7dfa06f6..902a7f9f3bd 100644 --- a/src/rules/arrayTypeRule.ts +++ b/src/rules/arrayTypeRule.ts @@ -164,6 +164,8 @@ function isSimpleType(nodeType: ts.TypeNode): boolean { case ts.SyntaxKind.ThisType: case ts.SyntaxKind.UnknownKeyword: return true; + case ts.SyntaxKind.ParenthesizedType: + return isSimpleType((nodeType as ts.ParenthesizedTypeNode).type); case ts.SyntaxKind.TypeReference: // TypeReferences must be non-generic or be another Array with a simple type const { typeName, typeArguments } = nodeType as ts.TypeReferenceNode; diff --git a/test/rules/array-type/array-simple/test.ts.fix b/test/rules/array-type/array-simple/test.ts.fix index 34ae5829b67..9fe94f1a5af 100644 --- a/test/rules/array-type/array-simple/test.ts.fix +++ b/test/rules/array-type/array-simple/test.ts.fix @@ -10,6 +10,8 @@ let yy: number[][] = [[4, 5], [6]]; let ya = [[1, "2"]] as Array<[number, string]>; type Arr = T[]; +type ParenthesisArr = (T)[]; +type DoubleParenthesisArr = ((T))[]; // Ignore user defined aliases let yyyy: Arr>>> = [[[["2"]]]]; @@ -38,9 +40,11 @@ let barVar: Array<(c: number) => number>; type fooUnion = Array; type barUnion = Array; +type bazUnion = Array<(string|number|boolean)>; type fooIntersection = Array; type barIntersection = Array; +type bazIntersection = Array<(string & number)>; namespace fooName { type BarType = { bar: string }; diff --git a/test/rules/array-type/array-simple/test.ts.lint b/test/rules/array-type/array-simple/test.ts.lint index 3177ea42985..18605baac0f 100644 --- a/test/rules/array-type/array-simple/test.ts.lint +++ b/test/rules/array-type/array-simple/test.ts.lint @@ -19,6 +19,8 @@ let ya = [[1, "2"]] as[number, string][]; type Arr = Array; ~~~~~~~~ [0] +type ParenthesisArr = (T)[]; +type DoubleParenthesisArr = ((T))[]; // Ignore user defined aliases let yyyy: Arr>[]> = [[[["2"]]]]; @@ -52,10 +54,14 @@ let barVar: ((c: number) => number)[]; type fooUnion = Array; type barUnion = (string|number|boolean)[]; ~~~~~~~~~~~~~~~~~~~~~~~~~ [Array type using 'T[]' is forbidden for non-simple types. Use 'Array' instead.] +type bazUnion = ((string|number|boolean))[]; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~ [Array type using 'T[]' is forbidden for non-simple types. Use 'Array' instead.] type fooIntersection = Array; type barIntersection = (string & number)[]; ~~~~~~~~~~~~~~~~~~~ [Array type using 'T[]' is forbidden for non-simple types. Use 'Array' instead.] +type bazIntersection = ((string & number))[]; + ~~~~~~~~~~~~~~~~~~~~~ [Array type using 'T[]' is forbidden for non-simple types. Use 'Array' instead.] namespace fooName { type BarType = { bar: string };