From 386fa3e1f6de1193539ed483362ece1375562292 Mon Sep 17 00:00:00 2001 From: Herrington Darkholme Date: Wed, 15 Jun 2016 20:54:56 +0800 Subject: [PATCH 1/6] improve error message for extending interface --- src/compiler/checker.ts | 22 +++++++++++++++++++++- src/compiler/diagnosticMessages.json | 4 ++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index a2fe0065983..d5f89bee8bf 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -852,7 +852,8 @@ namespace ts { if (!result) { if (nameNotFoundMessage) { - if (!checkAndReportErrorForMissingPrefix(errorLocation, name, nameArg)) { + if (!checkAndReportErrorForMissingPrefix(errorLocation, name, nameArg) && + !checkAndReportErrorForExtendingInterface(errorLocation, name)) { error(errorLocation, nameNotFoundMessage, typeof nameArg === "string" ? nameArg : declarationNameToString(nameArg)); } } @@ -936,6 +937,25 @@ namespace ts { return false; } + + function checkAndReportErrorForExtendingInterface(errorLocation: Node, name: string): boolean { + if (!errorLocation || errorLocation.kind !== SyntaxKind.Identifier || + !errorLocation.parent || !errorLocation.parent.parent || + errorLocation.parent.parent.kind !== SyntaxKind.HeritageClause) { + return false; + } + const heritageClause = errorLocation.parent.parent; + if (heritageClause.token !== SyntaxKind.ExtendsKeyword) { + return false; + } + const enclosingScope = heritageClause.parent.parent.locals; + if (enclosingScope && getSymbol(enclosingScope, name, SymbolFlags.Interface)) { + error(errorLocation, Diagnostics.Cannot_extend_an_interface_0_Did_you_mean_implements, name); + return true; + } + return false; + } + function checkResolvedBlockScopedVariable(result: Symbol, errorLocation: Node): void { Debug.assert((result.flags & SymbolFlags.BlockScopedVariable) !== 0); // Block-scoped variables cannot be used before their definition diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index b78c342481f..30a4e1575e5 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1935,6 +1935,10 @@ "category": "Error", "code": 2688 }, + "Cannot extend an interface '{0}'. Did you mean 'implements'?": { + "category": "Error", + "code": 2689 + }, "Import declaration '{0}' is using private name '{1}'.": { "category": "Error", "code": 4000 From 85434c59fcaad4919ad4e1545a9842495324c145 Mon Sep 17 00:00:00 2001 From: Herrington Darkholme Date: Wed, 15 Jun 2016 20:55:50 +0800 Subject: [PATCH 2/6] accept baselines --- .../reference/classExtendingClassLikeType.errors.txt | 4 ++-- .../reference/classExtendsEveryObjectType.errors.txt | 4 ++-- .../baselines/reference/classExtendsInterface.errors.txt | 8 ++++---- .../genericTypeReferenceWithoutTypeArgument2.errors.txt | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/baselines/reference/classExtendingClassLikeType.errors.txt b/tests/baselines/reference/classExtendingClassLikeType.errors.txt index 6f9aef927ea..5edefd78ec5 100644 --- a/tests/baselines/reference/classExtendingClassLikeType.errors.txt +++ b/tests/baselines/reference/classExtendingClassLikeType.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/classes/classDeclarations/classExtendingClassLikeType.ts(7,18): error TS2304: Cannot find name 'Base'. +tests/cases/conformance/classes/classDeclarations/classExtendingClassLikeType.ts(7,18): error TS2689: Cannot extend an interface 'Base'. Did you mean 'implements'? tests/cases/conformance/classes/classDeclarations/classExtendingClassLikeType.ts(45,18): error TS2508: No base constructor has the specified number of type arguments. tests/cases/conformance/classes/classDeclarations/classExtendingClassLikeType.ts(56,18): error TS2510: Base constructors must all have the same return type. @@ -12,7 +12,7 @@ tests/cases/conformance/classes/classDeclarations/classExtendingClassLikeType.ts // Error, no Base constructor function class D0 extends Base { ~~~~ -!!! error TS2304: Cannot find name 'Base'. +!!! error TS2689: Cannot extend an interface 'Base'. Did you mean 'implements'? } interface BaseConstructor { diff --git a/tests/baselines/reference/classExtendsEveryObjectType.errors.txt b/tests/baselines/reference/classExtendsEveryObjectType.errors.txt index 0339dfad13a..e1c5137e3a9 100644 --- a/tests/baselines/reference/classExtendsEveryObjectType.errors.txt +++ b/tests/baselines/reference/classExtendsEveryObjectType.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/classes/classDeclarations/classHeritageSpecification/classExtendsEveryObjectType.ts(4,17): error TS2304: Cannot find name 'I'. +tests/cases/conformance/classes/classDeclarations/classHeritageSpecification/classExtendsEveryObjectType.ts(4,17): error TS2689: Cannot extend an interface 'I'. Did you mean 'implements'? tests/cases/conformance/classes/classDeclarations/classHeritageSpecification/classExtendsEveryObjectType.ts(6,18): error TS2507: Type '{ foo: any; }' is not a constructor function type. tests/cases/conformance/classes/classDeclarations/classHeritageSpecification/classExtendsEveryObjectType.ts(6,25): error TS2304: Cannot find name 'string'. tests/cases/conformance/classes/classDeclarations/classHeritageSpecification/classExtendsEveryObjectType.ts(6,31): error TS1005: ',' expected. @@ -14,7 +14,7 @@ tests/cases/conformance/classes/classDeclarations/classHeritageSpecification/cla } class C extends I { } // error ~ -!!! error TS2304: Cannot find name 'I'. +!!! error TS2689: Cannot extend an interface 'I'. Did you mean 'implements'? class C2 extends { foo: string; } { } // error ~~~~~~~~~~~~~~~~ diff --git a/tests/baselines/reference/classExtendsInterface.errors.txt b/tests/baselines/reference/classExtendsInterface.errors.txt index 2ecca6cf2cf..3714bbb2323 100644 --- a/tests/baselines/reference/classExtendsInterface.errors.txt +++ b/tests/baselines/reference/classExtendsInterface.errors.txt @@ -1,17 +1,17 @@ -tests/cases/compiler/classExtendsInterface.ts(2,17): error TS2304: Cannot find name 'Comparable'. -tests/cases/compiler/classExtendsInterface.ts(6,21): error TS2304: Cannot find name 'Comparable2'. +tests/cases/compiler/classExtendsInterface.ts(2,17): error TS2689: Cannot extend an interface 'Comparable'. Did you mean 'implements'? +tests/cases/compiler/classExtendsInterface.ts(6,21): error TS2689: Cannot extend an interface 'Comparable2'. Did you mean 'implements'? ==== tests/cases/compiler/classExtendsInterface.ts (2 errors) ==== interface Comparable {} class A extends Comparable {} ~~~~~~~~~~ -!!! error TS2304: Cannot find name 'Comparable'. +!!! error TS2689: Cannot extend an interface 'Comparable'. Did you mean 'implements'? class B implements Comparable {} interface Comparable2 {} class A2 extends Comparable2 {} ~~~~~~~~~~~ -!!! error TS2304: Cannot find name 'Comparable2'. +!!! error TS2689: Cannot extend an interface 'Comparable2'. Did you mean 'implements'? class B2 implements Comparable2 {} \ No newline at end of file diff --git a/tests/baselines/reference/genericTypeReferenceWithoutTypeArgument2.errors.txt b/tests/baselines/reference/genericTypeReferenceWithoutTypeArgument2.errors.txt index e590ad42a7d..b6767a3b938 100644 --- a/tests/baselines/reference/genericTypeReferenceWithoutTypeArgument2.errors.txt +++ b/tests/baselines/reference/genericTypeReferenceWithoutTypeArgument2.errors.txt @@ -13,7 +13,7 @@ tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenc tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument2.ts(18,23): error TS2314: Generic type 'I' requires 1 type argument(s). tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument2.ts(18,27): error TS2314: Generic type 'I' requires 1 type argument(s). tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument2.ts(18,38): error TS2314: Generic type 'I' requires 1 type argument(s). -tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument2.ts(20,17): error TS2304: Cannot find name 'I'. +tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument2.ts(20,17): error TS2689: Cannot extend an interface 'I'. Did you mean 'implements'? tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument2.ts(23,21): error TS2314: Generic type 'I' requires 1 type argument(s). tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument2.ts(29,18): error TS2304: Cannot find name 'M'. tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument2.ts(30,24): error TS2314: Generic type 'E' requires 1 type argument(s). @@ -76,7 +76,7 @@ tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenc class D extends I { ~ -!!! error TS2304: Cannot find name 'I'. +!!! error TS2689: Cannot extend an interface 'I'. Did you mean 'implements'? } interface U extends I {} From c721b5f981de8ca1bd6e7b71fb5f17d9368d996f Mon Sep 17 00:00:00 2001 From: Herrington Darkholme Date: Fri, 17 Jun 2016 01:19:34 +0800 Subject: [PATCH 3/6] add tests & add branches for module interface --- src/compiler/checker.ts | 35 ++++++++++++------- tests/cases/compiler/classExtendsInterface.ts | 23 +++++++++++- 2 files changed, 44 insertions(+), 14 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index d5f89bee8bf..b0484fc890c 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -853,7 +853,7 @@ namespace ts { if (!result) { if (nameNotFoundMessage) { if (!checkAndReportErrorForMissingPrefix(errorLocation, name, nameArg) && - !checkAndReportErrorForExtendingInterface(errorLocation, name)) { + !checkAndReportErrorForExtendingInterface(errorLocation)) { error(errorLocation, nameNotFoundMessage, typeof nameArg === "string" ? nameArg : declarationNameToString(nameArg)); } } @@ -938,21 +938,30 @@ namespace ts { } - function checkAndReportErrorForExtendingInterface(errorLocation: Node, name: string): boolean { - if (!errorLocation || errorLocation.kind !== SyntaxKind.Identifier || - !errorLocation.parent || !errorLocation.parent.parent || - errorLocation.parent.parent.kind !== SyntaxKind.HeritageClause) { + function checkAndReportErrorForExtendingInterface(errorLocation: Node): boolean { + const container = getContainingClass(errorLocation); + const heritageClause = getAncestor(errorLocation, SyntaxKind.HeritageClause); + if (!container || !heritageClause || heritageClause.token !== SyntaxKind.ExtendsKeyword) { return false; } - const heritageClause = errorLocation.parent.parent; - if (heritageClause.token !== SyntaxKind.ExtendsKeyword) { - return false; + if (errorLocation.kind === SyntaxKind.Identifier) { + const name = (errorLocation).text; + const interfaceOrModule = resolveName( + errorLocation, name, + SymbolFlags.Interface | SymbolFlags.HasExports, + /*errorMessage*/ undefined, /*nameArg*/ undefined) + if (!interfaceOrModule) { + return false; + } + if (interfaceOrModule.flags & SymbolFlags.Interface) { + error(errorLocation, Diagnostics.Cannot_extend_an_interface_0_Did_you_mean_implements, name); + return true; + } } - const enclosingScope = heritageClause.parent.parent.locals; - if (enclosingScope && getSymbol(enclosingScope, name, SymbolFlags.Interface)) { - error(errorLocation, Diagnostics.Cannot_extend_an_interface_0_Did_you_mean_implements, name); - return true; + else if (errorLocation.kind === SyntaxKind.PropertyAccessExpression) { + // todo } + return false; } @@ -10058,7 +10067,7 @@ namespace ts { } const prop = getPropertyOfType(apparentType, right.text); if (!prop) { - if (right.text) { + if (right.text && !checkAndReportErrorForExtendingInterface(node)) { error(right, Diagnostics.Property_0_does_not_exist_on_type_1, declarationNameToString(right), typeToString(type.flags & TypeFlags.ThisType ? apparentType : type)); } return unknownType; diff --git a/tests/cases/compiler/classExtendsInterface.ts b/tests/cases/compiler/classExtendsInterface.ts index 36f42167d1a..883680619ed 100644 --- a/tests/cases/compiler/classExtendsInterface.ts +++ b/tests/cases/compiler/classExtendsInterface.ts @@ -1,7 +1,28 @@ interface Comparable {} class A extends Comparable {} class B implements Comparable {} - + interface Comparable2 {} class A2 extends Comparable2 {} class B2 implements Comparable2 {} + +function Factory(a: any): {new()} { + return null +} + +class C extends Factory(Comparable) {} + +module M { + export interface I1 {} + export interface I2 {} +} +class C1 extends M.I1 {} +class C2 extends M.I2 {} + +namespace N { + export interface I1 {} + export interface I2 {} +} + +class D1 extends N.I1 {} +class D2 extends N.I2 {} From 38962eea82f9bbb07c9657d0b7e2bb64d292c1a6 Mon Sep 17 00:00:00 2001 From: Herrington Darkholme Date: Fri, 17 Jun 2016 10:22:56 +0800 Subject: [PATCH 4/6] use resolveEntityName to find interface --- src/compiler/checker.ts | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index b0484fc890c..6081770f62e 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -939,29 +939,26 @@ namespace ts { function checkAndReportErrorForExtendingInterface(errorLocation: Node): boolean { - const container = getContainingClass(errorLocation); - const heritageClause = getAncestor(errorLocation, SyntaxKind.HeritageClause); - if (!container || !heritageClause || heritageClause.token !== SyntaxKind.ExtendsKeyword) { + let parentClassExpression = errorLocation; + while (parentClassExpression) { + const kind = parentClassExpression.kind; + if (kind === SyntaxKind.Identifier || kind === SyntaxKind.PropertyAccessExpression) { + parentClassExpression = parentClassExpression.parent; + continue; + } + if (kind === SyntaxKind.ExpressionWithTypeArguments) { + break; + } return false; } - if (errorLocation.kind === SyntaxKind.Identifier) { - const name = (errorLocation).text; - const interfaceOrModule = resolveName( - errorLocation, name, - SymbolFlags.Interface | SymbolFlags.HasExports, - /*errorMessage*/ undefined, /*nameArg*/ undefined) - if (!interfaceOrModule) { - return false; - } - if (interfaceOrModule.flags & SymbolFlags.Interface) { - error(errorLocation, Diagnostics.Cannot_extend_an_interface_0_Did_you_mean_implements, name); - return true; - } + if (!parentClassExpression) { + return false; } - else if (errorLocation.kind === SyntaxKind.PropertyAccessExpression) { - // todo + const expression = (parentClassExpression).expression; + if (resolveEntityName(expression, SymbolFlags.Interface, true)) { + error(errorLocation, Diagnostics.Cannot_extend_an_interface_0_Did_you_mean_implements, getTextOfNode(expression)); + return true; } - return false; } From 877977a4509bf9e2f2cec89108d389919975afe0 Mon Sep 17 00:00:00 2001 From: Herrington Darkholme Date: Fri, 17 Jun 2016 11:07:18 +0800 Subject: [PATCH 5/6] add new tests for extends interface --- src/compiler/checker.ts | 2 +- .../classExtendsInterface.errors.txt | 2 +- .../reference/classExtendsInterface.js | 2 +- ...assExtendsInterfaceInExpression.errors.txt | 14 ++++++ .../classExtendsInterfaceInExpression.js | 26 +++++++++++ .../classExtendsInterfaceInModule.errors.txt | 27 ++++++++++++ .../classExtendsInterfaceInModule.js | 44 +++++++++++++++++++ tests/cases/compiler/classExtendsInterface.ts | 21 --------- .../classExtendsInterfaceInExpression.ts | 7 +++ .../compiler/classExtendsInterfaceInModule.ts | 14 ++++++ 10 files changed, 135 insertions(+), 24 deletions(-) create mode 100644 tests/baselines/reference/classExtendsInterfaceInExpression.errors.txt create mode 100644 tests/baselines/reference/classExtendsInterfaceInExpression.js create mode 100644 tests/baselines/reference/classExtendsInterfaceInModule.errors.txt create mode 100644 tests/baselines/reference/classExtendsInterfaceInModule.js create mode 100644 tests/cases/compiler/classExtendsInterfaceInExpression.ts create mode 100644 tests/cases/compiler/classExtendsInterfaceInModule.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 6081770f62e..0cd9144e4be 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -955,7 +955,7 @@ namespace ts { return false; } const expression = (parentClassExpression).expression; - if (resolveEntityName(expression, SymbolFlags.Interface, true)) { + if (resolveEntityName(expression, SymbolFlags.Interface, /*ignoreErrors*/ true)) { error(errorLocation, Diagnostics.Cannot_extend_an_interface_0_Did_you_mean_implements, getTextOfNode(expression)); return true; } diff --git a/tests/baselines/reference/classExtendsInterface.errors.txt b/tests/baselines/reference/classExtendsInterface.errors.txt index 3714bbb2323..72b8466105c 100644 --- a/tests/baselines/reference/classExtendsInterface.errors.txt +++ b/tests/baselines/reference/classExtendsInterface.errors.txt @@ -8,7 +8,7 @@ tests/cases/compiler/classExtendsInterface.ts(6,21): error TS2689: Cannot extend ~~~~~~~~~~ !!! error TS2689: Cannot extend an interface 'Comparable'. Did you mean 'implements'? class B implements Comparable {} - + interface Comparable2 {} class A2 extends Comparable2 {} ~~~~~~~~~~~ diff --git a/tests/baselines/reference/classExtendsInterface.js b/tests/baselines/reference/classExtendsInterface.js index c06c4e66d8b..b324f7382d8 100644 --- a/tests/baselines/reference/classExtendsInterface.js +++ b/tests/baselines/reference/classExtendsInterface.js @@ -2,7 +2,7 @@ interface Comparable {} class A extends Comparable {} class B implements Comparable {} - + interface Comparable2 {} class A2 extends Comparable2 {} class B2 implements Comparable2 {} diff --git a/tests/baselines/reference/classExtendsInterfaceInExpression.errors.txt b/tests/baselines/reference/classExtendsInterfaceInExpression.errors.txt new file mode 100644 index 00000000000..a2f6e1f4b6c --- /dev/null +++ b/tests/baselines/reference/classExtendsInterfaceInExpression.errors.txt @@ -0,0 +1,14 @@ +tests/cases/compiler/classExtendsInterfaceInExpression.ts(7,25): error TS2304: Cannot find name 'A'. + + +==== tests/cases/compiler/classExtendsInterfaceInExpression.ts (1 errors) ==== + interface A {} + + function factory(a: any): {new(): Object} { + return null + } + + class C extends factory(A) {} + ~ +!!! error TS2304: Cannot find name 'A'. + \ No newline at end of file diff --git a/tests/baselines/reference/classExtendsInterfaceInExpression.js b/tests/baselines/reference/classExtendsInterfaceInExpression.js new file mode 100644 index 00000000000..1b4fa112cc8 --- /dev/null +++ b/tests/baselines/reference/classExtendsInterfaceInExpression.js @@ -0,0 +1,26 @@ +//// [classExtendsInterfaceInExpression.ts] +interface A {} + +function factory(a: any): {new(): Object} { + return null +} + +class C extends factory(A) {} + + +//// [classExtendsInterfaceInExpression.js] +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +function factory(a) { + return null; +} +var C = (function (_super) { + __extends(C, _super); + function C() { + _super.apply(this, arguments); + } + return C; +}(factory(A))); diff --git a/tests/baselines/reference/classExtendsInterfaceInModule.errors.txt b/tests/baselines/reference/classExtendsInterfaceInModule.errors.txt new file mode 100644 index 00000000000..9a87ddf51b6 --- /dev/null +++ b/tests/baselines/reference/classExtendsInterfaceInModule.errors.txt @@ -0,0 +1,27 @@ +tests/cases/compiler/classExtendsInterfaceInModule.ts(5,18): error TS2689: Cannot extend an interface 'M.I1'. Did you mean 'implements'? +tests/cases/compiler/classExtendsInterfaceInModule.ts(6,21): error TS2689: Cannot extend an interface 'M.I2'. Did you mean 'implements'? +tests/cases/compiler/classExtendsInterfaceInModule.ts(14,17): error TS2689: Cannot extend an interface 'Mod.Nested.I'. Did you mean 'implements'? + + +==== tests/cases/compiler/classExtendsInterfaceInModule.ts (3 errors) ==== + module M { + export interface I1 {} + export interface I2 {} + } + class C1 extends M.I1 {} + ~ +!!! error TS2689: Cannot extend an interface 'M.I1'. Did you mean 'implements'? + class C2 extends M.I2 {} + ~ +!!! error TS2689: Cannot extend an interface 'M.I2'. Did you mean 'implements'? + + module Mod { + export namespace Nested { + export interface I {} + } + } + + class D extends Mod.Nested.I {} + ~~~ +!!! error TS2689: Cannot extend an interface 'Mod.Nested.I'. Did you mean 'implements'? + \ No newline at end of file diff --git a/tests/baselines/reference/classExtendsInterfaceInModule.js b/tests/baselines/reference/classExtendsInterfaceInModule.js new file mode 100644 index 00000000000..45415488700 --- /dev/null +++ b/tests/baselines/reference/classExtendsInterfaceInModule.js @@ -0,0 +1,44 @@ +//// [classExtendsInterfaceInModule.ts] +module M { + export interface I1 {} + export interface I2 {} +} +class C1 extends M.I1 {} +class C2 extends M.I2 {} + +module Mod { + export namespace Nested { + export interface I {} + } +} + +class D extends Mod.Nested.I {} + + +//// [classExtendsInterfaceInModule.js] +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var C1 = (function (_super) { + __extends(C1, _super); + function C1() { + _super.apply(this, arguments); + } + return C1; +}(M.I1)); +var C2 = (function (_super) { + __extends(C2, _super); + function C2() { + _super.apply(this, arguments); + } + return C2; +}(M.I2)); +var D = (function (_super) { + __extends(D, _super); + function D() { + _super.apply(this, arguments); + } + return D; +}(Mod.Nested.I)); diff --git a/tests/cases/compiler/classExtendsInterface.ts b/tests/cases/compiler/classExtendsInterface.ts index 883680619ed..eaab1d60fc4 100644 --- a/tests/cases/compiler/classExtendsInterface.ts +++ b/tests/cases/compiler/classExtendsInterface.ts @@ -5,24 +5,3 @@ class B implements Comparable {} interface Comparable2 {} class A2 extends Comparable2 {} class B2 implements Comparable2 {} - -function Factory(a: any): {new()} { - return null -} - -class C extends Factory(Comparable) {} - -module M { - export interface I1 {} - export interface I2 {} -} -class C1 extends M.I1 {} -class C2 extends M.I2 {} - -namespace N { - export interface I1 {} - export interface I2 {} -} - -class D1 extends N.I1 {} -class D2 extends N.I2 {} diff --git a/tests/cases/compiler/classExtendsInterfaceInExpression.ts b/tests/cases/compiler/classExtendsInterfaceInExpression.ts new file mode 100644 index 00000000000..4dce2ae59bd --- /dev/null +++ b/tests/cases/compiler/classExtendsInterfaceInExpression.ts @@ -0,0 +1,7 @@ +interface A {} + +function factory(a: any): {new(): Object} { + return null +} + +class C extends factory(A) {} diff --git a/tests/cases/compiler/classExtendsInterfaceInModule.ts b/tests/cases/compiler/classExtendsInterfaceInModule.ts new file mode 100644 index 00000000000..4ea24e5dd7d --- /dev/null +++ b/tests/cases/compiler/classExtendsInterfaceInModule.ts @@ -0,0 +1,14 @@ +module M { + export interface I1 {} + export interface I2 {} +} +class C1 extends M.I1 {} +class C2 extends M.I2 {} + +module Mod { + export namespace Nested { + export interface I {} + } +} + +class D extends Mod.Nested.I {} From 2a9636b1beb87581536af331c90c343d821b76bc Mon Sep 17 00:00:00 2001 From: Herrington Darkholme Date: Fri, 17 Jun 2016 11:20:00 +0800 Subject: [PATCH 6/6] address code style --- .../reference/classExtendsInterfaceInExpression.errors.txt | 2 +- tests/baselines/reference/classExtendsInterfaceInExpression.js | 2 +- tests/cases/compiler/classExtendsInterfaceInExpression.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/baselines/reference/classExtendsInterfaceInExpression.errors.txt b/tests/baselines/reference/classExtendsInterfaceInExpression.errors.txt index a2f6e1f4b6c..64b160ea766 100644 --- a/tests/baselines/reference/classExtendsInterfaceInExpression.errors.txt +++ b/tests/baselines/reference/classExtendsInterfaceInExpression.errors.txt @@ -5,7 +5,7 @@ tests/cases/compiler/classExtendsInterfaceInExpression.ts(7,25): error TS2304: C interface A {} function factory(a: any): {new(): Object} { - return null + return null; } class C extends factory(A) {} diff --git a/tests/baselines/reference/classExtendsInterfaceInExpression.js b/tests/baselines/reference/classExtendsInterfaceInExpression.js index 1b4fa112cc8..69e63f92570 100644 --- a/tests/baselines/reference/classExtendsInterfaceInExpression.js +++ b/tests/baselines/reference/classExtendsInterfaceInExpression.js @@ -2,7 +2,7 @@ interface A {} function factory(a: any): {new(): Object} { - return null + return null; } class C extends factory(A) {} diff --git a/tests/cases/compiler/classExtendsInterfaceInExpression.ts b/tests/cases/compiler/classExtendsInterfaceInExpression.ts index 4dce2ae59bd..002631afedf 100644 --- a/tests/cases/compiler/classExtendsInterfaceInExpression.ts +++ b/tests/cases/compiler/classExtendsInterfaceInExpression.ts @@ -1,7 +1,7 @@ interface A {} function factory(a: any): {new(): Object} { - return null + return null; } class C extends factory(A) {}