8000 fix(eslint-plugin): use bracket for infer in array-type rule by armano2 · Pull Request #173 · typescript-eslint/typescript-eslint · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

8000 Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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