Skip to content

Commit

Permalink
callable-types: add parens inside ArrayType (palantir#3440)
Browse files Browse the repository at this point in the history
[bugfix] `callable-types` adds parentheses when fixing a type literal inside an array type
  • Loading branch information
ajafff authored and HyphnKnight committed Apr 9, 2018
1 parent 526ca52 commit 77d2c1f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/rules/callableTypesRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ function shouldWrapSuggestion(parent: ts.Node) {
switch (parent.kind) {
case ts.SyntaxKind.UnionType:
case ts.SyntaxKind.IntersectionType:
case ts.SyntaxKind.ArrayType:
return true;
default:
return false;
Expand Down
2 changes: 2 additions & 0 deletions test/rules/callable-types/test.ts.fix
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ function f(x: string | (() => void)): void;
function f(x: (() => string) | (() => number)): void;
function f(x: string & (() => void)): void;
function f(x: (() => string) & (() => number)): void;
function f(x: (() => string)[]): void;

// Overloads OK
interface K {
Expand All @@ -28,3 +29,4 @@ interface K {
export type I = () => void;

export type T = () => void

4 changes: 3 additions & 1 deletion test/rules/callable-types/test.ts.lint
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ function f(x: string & { (): void }): void;
function f(x: { (): string } & { (): number }): void;
~~~~~~~~~~ [type % ('(() => string)')]
~~~~~~~~~~ [type % ('(() => number)')]
function f(x: { (): string }[]): void;
~~~~~~~~~~ [type % ('(() => string)')]

// Overloads OK
interface K {
Expand All @@ -64,4 +66,4 @@ export type T = {

[_base]: %s has only a call signature — use `%s` instead.
[interface]: _base % ('Interface')
[type]: _base % ('Type literal')
[type]: _base % ('Type literal')

0 comments on commit 77d2c1f

Please sign in to comment.