Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

Commit

Permalink
no-empty-interface: allow providing type arguments for extended type (#…
Browse files Browse the repository at this point in the history
…3260)

[bugfix] `no-empty-interface` allows providing type arguments for extended type
Fixes: #3256
  • Loading branch information
ajafff authored and adidahiya committed Oct 20, 2017
1 parent 94d1cfd commit 561cb58
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/rules/noEmptyInterfaceRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,22 @@ function walk(ctx: Lint.WalkContext<void>) {
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);
}
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
}
}
2 changes: 2 additions & 0 deletions test/rules/no-empty-interface/test.ts.lint
Original file line number Diff line number Diff line change
Expand Up @@ -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<string|number> {}

0 comments on commit 561cb58

Please sign in to comment.