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
8000

fix(eslint-plugin): use bracket for infer in array-type rule #173

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

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
8000
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