diff --git a/packages/eslint-plugin/lib/rules/array-type.js b/packages/eslint-plugin/lib/rules/array-type.js index 9d30f23cfb4f..ba7d83a5a7f5 100644 --- a/packages/eslint-plugin/lib/rules/array-type.js +++ b/packages/eslint-plugin/lib/rules/array-type.js @@ -67,6 +67,7 @@ function typeNeedsParentheses(node) { case 'TSFunctionType': case 'TSIntersectionType': case 'TSTypeOperator': + case 'TSInferType': return true; default: return false; diff --git a/packages/eslint-plugin/tests/lib/rules/array-type.js b/packages/eslint-plugin/tests/lib/rules/array-type.js index e39796f90c0d..39716675cf1c 100644 --- a/packages/eslint-plugin/tests/lib/rules/array-type.js +++ b/packages/eslint-plugin/tests/lib/rules/array-type.js @@ -138,6 +138,11 @@ ruleTester.run('array-type', rule, { }`, options: ['array'] }, + { + // https://github.com/typescript-eslint/typescript-eslint/issues/172 + code: 'type Unwrap = T extends (infer E)[] ? E : T', + options: ['array'] + }, { code: `let z: Array = [3, "4"];`, options: ['generic'] @@ -173,6 +178,11 @@ ruleTester.run('array-type', rule, { { code: `type fooIntersection = Array;`, options: ['generic'] + }, + { + // https://github.com/typescript-eslint/typescript-eslint/issues/172 + code: 'type Unwrap = T extends Array ? E : T', + options: ['generic'] } ], invalid: [ @@ -774,6 +784,34 @@ let yyyy: Arr>>> = [[[["2"]]]];`, column: 19 } ] + }, + { + // https://github.com/typescript-eslint/typescript-eslint/issues/172 + code: 'type Unwrap = T extends Array ? E : T', + output: 'type Unwrap = T extends (infer E)[] ? E : T', + options: ['array'], + errors: [ + { + messageId: 'errorStringArray', + data: { type: 'T' }, + line: 1, + column: 28 + } + ] + }, + { + // https://github.com/typescript-eslint/typescript-eslint/issues/172 + code: 'type Unwrap = T extends (infer E)[] ? E : T', + output: 'type Unwrap = T extends Array ? E : T', + options: ['generic'], + errors: [ + { + messageId: 'errorStringGeneric', + data: { type: 'T' }, + line: 1, + column: 28 + } + ] } ] });