From 77d2c1fd65fdacf1ed05f01fbed8ba00ae737191 Mon Sep 17 00:00:00 2001 From: Klaus Meinhardt Date: Tue, 9 Jan 2018 21:16:12 +0100 Subject: [PATCH] callable-types: add parens inside ArrayType (#3440) [bugfix] `callable-types` adds parentheses when fixing a type literal inside an array type --- src/rules/callableTypesRule.ts | 1 + test/rules/callable-types/test.ts.fix | 2 ++ test/rules/callable-types/test.ts.lint | 4 +++- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/rules/callableTypesRule.ts b/src/rules/callableTypesRule.ts index 8c3ce1e991c..75c85898d6f 100644 --- a/src/rules/callableTypesRule.ts +++ b/src/rules/callableTypesRule.ts @@ -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; diff --git a/test/rules/callable-types/test.ts.fix b/test/rules/callable-types/test.ts.fix index b1d6b8e62ff..e82feeb5cf7 100644 --- a/test/rules/callable-types/test.ts.fix +++ b/test/rules/callable-types/test.ts.fix @@ -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 { @@ -28,3 +29,4 @@ interface K { export type I = () => void; export type T = () => void + diff --git a/test/rules/callable-types/test.ts.lint b/test/rules/callable-types/test.ts.lint index 363425ec370..7f9c3719aa8 100644 --- a/test/rules/callable-types/test.ts.lint +++ b/test/rules/callable-types/test.ts.lint @@ -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 { @@ -64,4 +66,4 @@ export type T = { [_base]: %s has only a call signature — use `%s` instead. [interface]: _base % ('Interface') -[type]: _base % ('Type literal') \ No newline at end of file +[type]: _base % ('Type literal')