From 561cb5829c5b6d7b131b2806bde3b021e95eea5c Mon Sep 17 00:00:00 2001 From: Klaus Meinhardt Date: Fri, 20 Oct 2017 06:12:30 +0200 Subject: [PATCH] no-empty-interface: allow providing type arguments for extended type (#3260) [bugfix] `no-empty-interface` allows providing type arguments for extended type Fixes: #3256 --- src/rules/noEmptyInterfaceRule.ts | 15 ++++++++++++--- test/rules/no-empty-interface/test.ts.lint | 2 ++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/rules/noEmptyInterfaceRule.ts b/src/rules/noEmptyInterfaceRule.ts index eb06d57ae7a..5bb9e1e59df 100644 --- a/src/rules/noEmptyInterfaceRule.ts +++ b/src/rules/noEmptyInterfaceRule.ts @@ -45,9 +45,7 @@ function walk(ctx: Lint.WalkContext) { return ts.forEachChild(ctx.sourceFile, function cb(node: ts.Node): void { if (isInterfaceDeclaration(node) && node.members.length === 0 && - (node.heritageClauses === undefined || - // allow interfaces that extend 2 or more interfaces - node.heritageClauses[0].types.length < 2)) { + (node.heritageClauses === undefined || extendsOneTypeWithoutTypeArguments(node.heritageClauses[0]))) { return ctx.addFailureAtNode( node.name, node.heritageClauses !== undefined ? Rule.FAILURE_STRING_FOR_EXTENDS : Rule.FAILURE_STRING); @@ -55,3 +53,14 @@ function walk(ctx: Lint.WalkContext) { return ts.forEachChild(node, cb); }); } + +function extendsOneTypeWithoutTypeArguments({types}: ts.HeritageClause): boolean { + switch (types.length) { + case 0: + return true; // don't crash on empty extends list + case 1: + return types[0].typeArguments === undefined; // allow interfaces that provide type arguments for the extended type + default: + return false; // allow interfaces extending more than one types + } +} diff --git a/test/rules/no-empty-interface/test.ts.lint b/test/rules/no-empty-interface/test.ts.lint index b60398d65c8..b740fc1d6cd 100644 --- a/test/rules/no-empty-interface/test.ts.lint +++ b/test/rules/no-empty-interface/test.ts.lint @@ -10,3 +10,5 @@ interface L extends J, K {} // extending more than one interface is ok, as it ca interface M extends {} // don't crash on empty extends list ~ [An interface declaring no members is equivalent to its supertype.] + +interface N extends Promise {}