add tests & add branches for module interface
This commit is contained in:
parent
85434c59fc
commit
c721b5f981
2 changed files with 44 additions and 14 deletions
|
@ -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 = <HeritageClause>getAncestor(errorLocation, SyntaxKind.HeritageClause);
|
||||
if (!container || !heritageClause || heritageClause.token !== SyntaxKind.ExtendsKeyword) {
|
||||
return false;
|
||||
}
|
||||
const heritageClause = <HeritageClause>errorLocation.parent.parent;
|
||||
if (heritageClause.token !== SyntaxKind.ExtendsKeyword) {
|
||||
return false;
|
||||
if (errorLocation.kind === SyntaxKind.Identifier) {
|
||||
const name = (<Identifier>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;
|
||||
|
|
|
@ -1,7 +1,28 @@
|
|||
interface Comparable {}
|
||||
class A extends Comparable {}
|
||||
class B implements Comparable {}
|
||||
|
||||
|
||||
interface Comparable2<T> {}
|
||||
class A2<T> extends Comparable2<T> {}
|
||||
class B2<T> implements Comparable2<T> {}
|
||||
|
||||
function Factory(a: any): {new()} {
|
||||
return null
|
||||
}
|
||||
|
||||
class C extends Factory(Comparable) {}
|
||||
|
||||
module M {
|
||||
export interface I1 {}
|
||||
export interface I2<T> {}
|
||||
}
|
||||
class C1 extends M.I1 {}
|
||||
class C2<T> extends M.I2<T> {}
|
||||
|
||||
namespace N {
|
||||
export interface I1 {}
|
||||
export interface I2<T> {}
|
||||
}
|
||||
|
||||
class D1 extends N.I1 {}
|
||||
class D2<T> extends N.I2<T> {}
|
||||
|
|
Loading…
Reference in a new issue