Skip to content

Commit

Permalink
fix(eslint-plugin): use bracket for infer type in array-type rule (#173)
Browse files Browse the repository at this point in the history
  • Loading branch information
armano2 committed Jan 31, 2019
1 parent f0dddbc commit 1f868ce
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/eslint-plugin/lib/rules/array-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ function typeNeedsParentheses(node) {
case 'TSFunctionType':
case 'TSIntersectionType':
case 'TSTypeOperator':
case 'TSInferType':
return true;
default:
return false;
Expand Down
38 changes: 38 additions & 0 deletions packages/eslint-plugin/tests/lib/rules/array-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ ruleTester.run('array-type', rule, {
}`,
options: ['array']
},
{
// https://github.com/typescript-eslint/typescript-eslint/issues/172
code: 'type Unwrap<T> = T extends (infer E)[] ? E : T',
options: ['array']
},
{
code: `let z: Array = [3, "4"];`,
options: ['generic']
Expand Down Expand Up @@ -173,6 +178,11 @@ ruleTester.run('array-type', rule, {
{
code: `type fooIntersection = Array<string & number>;`,
options: ['generic']
},
{
// https://github.com/typescript-eslint/typescript-eslint/issues/172
code: 'type Unwrap<T> = T extends Array<infer E> ? E : T',
options: ['generic']
}
],
invalid: [
Expand Down Expand Up @@ -774,6 +784,34 @@ let yyyy: Arr<Array<Array<Arr<string>>>> = [[[["2"]]]];`,
column: 19
}
]
},
{
// https://github.com/typescript-eslint/typescript-eslint/issues/172
code: 'type Unwrap<T> = T extends Array<infer E> ? E : T',
output: 'type Unwrap<T> = 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> = T extends (infer E)[] ? E : T',
output: 'type Unwrap<T> = T extends Array<infer E> ? E : T',
options: ['generic'],
errors: [
{
messageId: 'errorStringGeneric',
data: { type: 'T' },
line: 1,
column: 28
}
]
}
]
});
Expand Down

0 comments on commit 1f868ce

Please sign in to comment.