Merge pull request #3333 from aozgaa/mergedDeclarationClassInterface

Merged Declarations for Classes and Interfaces
This commit is contained in:
Arthur Ozga 2015-07-02 10:41:43 -07:00
commit 6775d88da3
47 changed files with 1163 additions and 138 deletions

View File

@ -173,6 +173,14 @@ namespace ts {
return node.name ? declarationNameToString(node.name) : getDeclarationName(node);
}
/**
* Declares a Symbol for the node and adds it to symbols. Reports errors for conflicting identifier names.
* @param symbolTable - The symbol table which node will be added to.
* @param parent - node's parent declaration.
* @param node - The declaration to be added to the symbol table
* @param includes - The SymbolFlags that node has in addition to its declaration type (eg: export, ambient, etc.)
* @param excludes - The flags which node cannot be declared alongside in a symbol table. Used to report forbidden declarations.
*/
function declareSymbol(symbolTable: SymbolTable, parent: Symbol, node: Declaration, includes: SymbolFlags, excludes: SymbolFlags): Symbol {
Debug.assert(!hasDynamicName(node));
@ -181,10 +189,11 @@ namespace ts {
let symbol: Symbol;
if (name !== undefined) {
// Check and see if the symbol table already has a symbol with this name. If not,
// create a new symbol with this name and add it to the table. Note that we don't
// give the new symbol any flags *yet*. This ensures that it will not conflict
// witht he 'excludes' flags we pass in.
// with the 'excludes' flags we pass in.
//
// If we do get an existing symbol, see if it conflicts with the new symbol we're
// creating. For example, a 'var' symbol and a 'class' symbol will conflict within
@ -202,10 +211,10 @@ namespace ts {
symbol = hasProperty(symbolTable, name)
? symbolTable[name]
: (symbolTable[name] = createSymbol(SymbolFlags.None, name));
if (name && (includes & SymbolFlags.Classifiable)) {
classifiableNames[name] = name;
}
classifiableNames[name] = name;
}
if (symbol.flags & excludes) {
if (node.name) {
@ -314,6 +323,7 @@ namespace ts {
addToContainerChain(container);
}
else if (containerFlags & ContainerFlags.IsBlockScopedContainer) {
blockScopeContainer = node;
blockScopeContainer.locals = undefined;

View File

@ -12034,6 +12034,12 @@ namespace ts {
grammarErrorOnFirstToken(node, Diagnostics.A_class_declaration_without_the_default_modifier_must_have_a_name);
}
checkClassLikeDeclaration(node);
// Interfaces cannot be merged with non-ambient classes.
if (getSymbolOfNode(node).flags & SymbolFlags.Interface && !isInAmbientContext(node)) {
error(node, Diagnostics.Only_an_ambient_class_can_be_merged_with_an_interface)
}
forEach(node.members, checkSourceElement);
}
@ -12306,6 +12312,16 @@ namespace ts {
checkIndexConstraints(type);
}
}
// Interfaces cannot merge with non-ambient classes.
if (symbol && symbol.declarations) {
for (let declaration of symbol.declarations) {
if (declaration.kind === SyntaxKind.ClassDeclaration && !isInAmbientContext(declaration)) {
error(node, Diagnostics.Only_an_ambient_class_can_be_merged_with_an_interface);
break;
}
}
}
}
forEach(getInterfaceBaseTypeNodes(node), heritageElement => {
if (!isSupportedExpressionWithTypeArguments(heritageElement)) {
@ -12313,6 +12329,7 @@ namespace ts {
}
checkTypeReferenceNode(heritageElement);
});
forEach(node.members, checkSourceElement);
if (produceDiagnostics) {

View File

@ -408,6 +408,7 @@ namespace ts {
Non_abstract_class_0_does_not_implement_inherited_abstract_member_1_from_class_2: { code: 2515, category: DiagnosticCategory.Error, key: "Non-abstract class '{0}' does not implement inherited abstract member '{1}' from class '{2}'." },
All_declarations_of_an_abstract_method_must_be_consecutive: { code: 2516, category: DiagnosticCategory.Error, key: "All declarations of an abstract method must be consecutive." },
Constructor_objects_of_abstract_type_cannot_be_assigned_to_constructor_objects_of_non_abstract_type: { code: 2517, category: DiagnosticCategory.Error, key: "Constructor objects of abstract type cannot be assigned to constructor objects of non-abstract type" },
Only_an_ambient_class_can_be_merged_with_an_interface: { code: 2518, category: DiagnosticCategory.Error, key: "Only an ambient class can be merged with an interface." },
Duplicate_identifier_0_Compiler_uses_declaration_1_to_support_async_functions: { code: 2520, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'. Compiler uses declaration '{1}' to support async functions." },
Expression_resolves_to_variable_declaration_0_that_compiler_uses_to_support_async_functions: { code: 2521, category: DiagnosticCategory.Error, key: "Expression resolves to variable declaration '{0}' that compiler uses to support async functions." },
The_arguments_object_cannot_be_referenced_in_an_async_arrow_function_Consider_using_a_standard_async_function_expression: { code: 2522, category: DiagnosticCategory.Error, key: "The 'arguments' object cannot be referenced in an async arrow function. Consider using a standard async function expression." },

View File

@ -1621,6 +1621,10 @@
"category": "Error",
"code":2517
},
"Only an ambient class can be merged with an interface.": {
"category": "Error",
"code": 2518
},
"Duplicate identifier '{0}'. Compiler uses declaration '{1}' to support async functions.": {
"category": "Error",
"code": 2520

View File

@ -1597,8 +1597,8 @@ namespace ts {
PropertyExcludes = Value,
EnumMemberExcludes = Value,
FunctionExcludes = Value & ~(Function | ValueModule),
ClassExcludes = (Value | Type) & ~ValueModule,
InterfaceExcludes = Type & ~Interface,
ClassExcludes = (Value | Type) & ~(ValueModule | Interface), // class-interface mergability done in checker.ts
InterfaceExcludes = Type & ~(Interface | Class),
RegularEnumExcludes = (Value | Type) & ~(RegularEnum | ValueModule), // regular enums merge only with regular enums and modules
ConstEnumExcludes = (Value | Type) & ~ConstEnum, // const enums merge only with const enums
ValueModuleExcludes = Value & ~(Function | Class | RegularEnum | ValueModule),

View File

@ -1,5 +1,5 @@
tests/cases/compiler/augmentedTypesClass2.ts(4,7): error TS2300: Duplicate identifier 'c11'.
tests/cases/compiler/augmentedTypesClass2.ts(10,11): error TS2300: Duplicate identifier 'c11'.
tests/cases/compiler/augmentedTypesClass2.ts(4,7): error TS2518: Only an ambient class can be merged with an interface.
tests/cases/compiler/augmentedTypesClass2.ts(10,11): error TS2518: Only an ambient class can be merged with an interface.
tests/cases/compiler/augmentedTypesClass2.ts(16,7): error TS2300: Duplicate identifier 'c33'.
tests/cases/compiler/augmentedTypesClass2.ts(21,6): error TS2300: Duplicate identifier 'c33'.
@ -10,7 +10,7 @@ tests/cases/compiler/augmentedTypesClass2.ts(21,6): error TS2300: Duplicate iden
// class then interface
class c11 { // error
~~~
!!! error TS2300: Duplicate identifier 'c11'.
!!! error TS2518: Only an ambient class can be merged with an interface.
foo() {
return 1;
}
@ -18,7 +18,7 @@ tests/cases/compiler/augmentedTypesClass2.ts(21,6): error TS2300: Duplicate iden
interface c11 { // error
~~~
!!! error TS2300: Duplicate identifier 'c11'.
!!! error TS2518: Only an ambient class can be merged with an interface.
bar(): void;
}

View File

@ -1,5 +1,5 @@
tests/cases/compiler/augmentedTypesInterface.ts(12,11): error TS2300: Duplicate identifier 'i2'.
tests/cases/compiler/augmentedTypesInterface.ts(16,7): error TS2300: Duplicate identifier 'i2'.
tests/cases/compiler/augmentedTypesInterface.ts(12,11): error TS2518: Only an ambient class can be merged with an interface.
tests/cases/compiler/augmentedTypesInterface.ts(16,7): error TS2518: Only an ambient class can be merged with an interface.
tests/cases/compiler/augmentedTypesInterface.ts(23,11): error TS2300: Duplicate identifier 'i3'.
tests/cases/compiler/augmentedTypesInterface.ts(26,6): error TS2300: Duplicate identifier 'i3'.
@ -18,13 +18,13 @@ tests/cases/compiler/augmentedTypesInterface.ts(26,6): error TS2300: Duplicate i
// interface then class
interface i2 { // error
~~
!!! error TS2300: Duplicate identifier 'i2'.
!!! error TS2518: Only an ambient class can be merged with an interface.
foo(): void;
}
class i2 { // error
~~
!!! error TS2300: Duplicate identifier 'i2'.
!!! error TS2518: Only an ambient class can be merged with an interface.
bar() {
return 1;
}

View File

@ -1,11 +0,0 @@
tests/cases/compiler/class1.ts(1,11): error TS2300: Duplicate identifier 'foo'.
tests/cases/compiler/class1.ts(2,7): error TS2300: Duplicate identifier 'foo'.
==== tests/cases/compiler/class1.ts (2 errors) ====
interface foo{ } // error
~~~
!!! error TS2300: Duplicate identifier 'foo'.
class foo{ } // error
~~~
!!! error TS2300: Duplicate identifier 'foo'.

View File

@ -1,10 +0,0 @@
//// [class1.ts]
interface foo{ } // error
class foo{ } // error
//// [class1.js]
var foo = (function () {
function foo() {
}
return foo;
})(); // error

View File

@ -1,19 +1,26 @@
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractMergedDeclaration.ts(7,16): error TS2300: Duplicate identifier 'CI'.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractMergedDeclaration.ts(8,11): error TS2300: Duplicate identifier 'CI'.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractMergedDeclaration.ts(10,11): error TS2300: Duplicate identifier 'IC'.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractMergedDeclaration.ts(11,16): error TS2300: Duplicate identifier 'IC'.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractMergedDeclaration.ts(7,16): error TS2518: Only an ambient class can be merged with an interface.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractMergedDeclaration.ts(8,11): error TS2518: Only an ambient class can be merged with an interface.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractMergedDeclaration.ts(10,11): error TS2518: Only an ambient class can be merged with an interface.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractMergedDeclaration.ts(11,16): error TS2518: Only an ambient class can be merged with an interface.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractMergedDeclaration.ts(13,16): error TS2300: Duplicate identifier 'CC1'.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractMergedDeclaration.ts(14,7): error TS2300: Duplicate identifier 'CC1'.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractMergedDeclaration.ts(16,7): error TS2300: Duplicate identifier 'CC2'.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractMergedDeclaration.ts(17,16): error TS2300: Duplicate identifier 'CC2'.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractMergedDeclaration.ts(19,1): error TS2511: Cannot create an instance of the abstract class 'CM'.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractMergedDeclaration.ts(20,1): error TS2511: Cannot create an instance of the abstract class 'MC'.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractMergedDeclaration.ts(21,1): error TS2511: Cannot create an instance of the abstract class 'CI'.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractMergedDeclaration.ts(22,5): error TS2304: Cannot find name 'IC'.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractMergedDeclaration.ts(23,1): error TS2511: Cannot create an instance of the abstract class 'CC1'.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractMergedDeclaration.ts(25,24): error TS2300: Duplicate identifier 'DCC1'.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractMergedDeclaration.ts(26,15): error TS2300: Duplicate identifier 'DCC1'.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractMergedDeclaration.ts(28,15): error TS2300: Duplicate identifier 'DCC2'.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractMergedDeclaration.ts(29,24): error TS2300: Duplicate identifier 'DCC2'.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractMergedDeclaration.ts(31,1): error TS2511: Cannot create an instance of the abstract class 'CM'.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractMergedDeclaration.ts(32,1): error TS2511: Cannot create an instance of the abstract class 'MC'.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractMergedDeclaration.ts(33,1): error TS2511: Cannot create an instance of the abstract class 'CI'.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractMergedDeclaration.ts(34,1): error TS2511: Cannot create an instance of the abstract class 'IC'.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractMergedDeclaration.ts(35,1): error TS2511: Cannot create an instance of the abstract class 'CC1'.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractMergedDeclaration.ts(37,1): error TS2511: Cannot create an instance of the abstract class 'DCI'.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractMergedDeclaration.ts(38,1): error TS2511: Cannot create an instance of the abstract class 'DIC'.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractMergedDeclaration.ts(39,1): error TS2511: Cannot create an instance of the abstract class 'DCC1'.
==== tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractMergedDeclaration.ts (13 errors) ====
==== tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractMergedDeclaration.ts (20 errors) ====
abstract class CM {}
module CM {}
@ -22,17 +29,17 @@ tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbst
abstract class CI {}
~~
!!! error TS2300: Duplicate identifier 'CI'.
!!! error TS2518: Only an ambient class can be merged with an interface.
interface CI {}
~~
!!! error TS2300: Duplicate identifier 'CI'.
!!! error TS2518: Only an ambient class can be merged with an interface.
interface IC {}
~~
!!! error TS2300: Duplicate identifier 'IC'.
!!! error TS2518: Only an ambient class can be merged with an interface.
abstract class IC {}
~~
!!! error TS2300: Duplicate identifier 'IC'.
!!! error TS2518: Only an ambient class can be merged with an interface.
abstract class CC1 {}
~~~
@ -48,6 +55,26 @@ tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbst
~~~
!!! error TS2300: Duplicate identifier 'CC2'.
declare abstract class DCI {}
interface DCI {}
interface DIC {}
declare abstract class DIC {}
declare abstract class DCC1 {}
~~~~
!!! error TS2300: Duplicate identifier 'DCC1'.
declare class DCC1 {}
~~~~
!!! error TS2300: Duplicate identifier 'DCC1'.
declare class DCC2 {}
~~~~
!!! error TS2300: Duplicate identifier 'DCC2'.
declare abstract class DCC2 {}
~~~~
!!! error TS2300: Duplicate identifier 'DCC2'.
new CM;
~~~~~~
!!! error TS2511: Cannot create an instance of the abstract class 'CM'.
@ -58,9 +85,19 @@ tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbst
~~~~~~
!!! error TS2511: Cannot create an instance of the abstract class 'CI'.
new IC;
~~
!!! error TS2304: Cannot find name 'IC'.
~~~~~~
!!! error TS2511: Cannot create an instance of the abstract class 'IC'.
new CC1;
~~~~~~~
!!! error TS2511: Cannot create an instance of the abstract class 'CC1'.
new CC2;
new CC2;
new DCI;
~~~~~~~
!!! error TS2511: Cannot create an instance of the abstract class 'DCI'.
new DIC;
~~~~~~~
!!! error TS2511: Cannot create an instance of the abstract class 'DIC'.
new DCC1;
~~~~~~~~
!!! error TS2511: Cannot create an instance of the abstract class 'DCC1'.
new DCC2;

View File

@ -17,12 +17,28 @@ class CC1 {}
class CC2 {}
abstract class CC2 {}
declare abstract class DCI {}
interface DCI {}
interface DIC {}
declare abstract class DIC {}
declare abstract class DCC1 {}
declare class DCC1 {}
declare class DCC2 {}
declare abstract class DCC2 {}
new CM;
new MC;
new CI;
new IC;
new CC1;
new CC2;
new CC2;
new DCI;
new DIC;
new DCC1;
new DCC2;
//// [classAbstractMergedDeclaration.js]
var CM = (function () {
@ -71,3 +87,7 @@ new CI;
new IC;
new CC1;
new CC2;
new DCI;
new DIC;
new DCC1;
new DCC2;

View File

@ -1,11 +0,0 @@
tests/cases/compiler/classAndInterface1.ts(1,8): error TS2300: Duplicate identifier 'cli'.
tests/cases/compiler/classAndInterface1.ts(2,11): error TS2300: Duplicate identifier 'cli'.
==== tests/cases/compiler/classAndInterface1.ts (2 errors) ====
class cli { } // error
~~~
!!! error TS2300: Duplicate identifier 'cli'.
interface cli { } // error
~~~
!!! error TS2300: Duplicate identifier 'cli'.

View File

@ -1,10 +0,0 @@
//// [classAndInterface1.ts]
class cli { } // error
interface cli { } // error
//// [classAndInterface1.js]
var cli = (function () {
function cli() {
}
return cli;
})(); // error

View File

@ -0,0 +1,39 @@
=== tests/cases/conformance/classes/classDeclarations/classAndInterfaceMerge.d.ts ===
interface C { }
>C : Symbol(C, Decl(classAndInterfaceMerge.d.ts, 0, 0), Decl(classAndInterfaceMerge.d.ts, 1, 15), Decl(classAndInterfaceMerge.d.ts, 3, 19), Decl(classAndInterfaceMerge.d.ts, 5, 15))
declare class C { }
>C : Symbol(C, Decl(classAndInterfaceMerge.d.ts, 0, 0), Decl(classAndInterfaceMerge.d.ts, 1, 15), Decl(classAndInterfaceMerge.d.ts, 3, 19), Decl(classAndInterfaceMerge.d.ts, 5, 15))
interface C { }
>C : Symbol(C, Decl(classAndInterfaceMerge.d.ts, 0, 0), Decl(classAndInterfaceMerge.d.ts, 1, 15), Decl(classAndInterfaceMerge.d.ts, 3, 19), Decl(classAndInterfaceMerge.d.ts, 5, 15))
interface C { }
>C : Symbol(C, Decl(classAndInterfaceMerge.d.ts, 0, 0), Decl(classAndInterfaceMerge.d.ts, 1, 15), Decl(classAndInterfaceMerge.d.ts, 3, 19), Decl(classAndInterfaceMerge.d.ts, 5, 15))
declare module M {
>M : Symbol(M, Decl(classAndInterfaceMerge.d.ts, 7, 15), Decl(classAndInterfaceMerge.d.ts, 20, 1))
interface C1 { }
>C1 : Symbol(C1, Decl(classAndInterfaceMerge.d.ts, 9, 18), Decl(classAndInterfaceMerge.d.ts, 11, 20), Decl(classAndInterfaceMerge.d.ts, 13, 16), Decl(classAndInterfaceMerge.d.ts, 15, 20))
class C1 { }
>C1 : Symbol(C1, Decl(classAndInterfaceMerge.d.ts, 9, 18), Decl(classAndInterfaceMerge.d.ts, 11, 20), Decl(classAndInterfaceMerge.d.ts, 13, 16), Decl(classAndInterfaceMerge.d.ts, 15, 20))
interface C1 { }
>C1 : Symbol(C1, Decl(classAndInterfaceMerge.d.ts, 9, 18), Decl(classAndInterfaceMerge.d.ts, 11, 20), Decl(classAndInterfaceMerge.d.ts, 13, 16), Decl(classAndInterfaceMerge.d.ts, 15, 20))
interface C1 { }
>C1 : Symbol(C1, Decl(classAndInterfaceMerge.d.ts, 9, 18), Decl(classAndInterfaceMerge.d.ts, 11, 20), Decl(classAndInterfaceMerge.d.ts, 13, 16), Decl(classAndInterfaceMerge.d.ts, 15, 20))
export class C2 { }
>C2 : Symbol(C2, Decl(classAndInterfaceMerge.d.ts, 17, 20), Decl(classAndInterfaceMerge.d.ts, 22, 18))
}
declare module M {
>M : Symbol(M, Decl(classAndInterfaceMerge.d.ts, 7, 15), Decl(classAndInterfaceMerge.d.ts, 20, 1))
export interface C2 { }
>C2 : Symbol(C2, Decl(classAndInterfaceMerge.d.ts, 17, 20), Decl(classAndInterfaceMerge.d.ts, 22, 18))
}

View File

@ -0,0 +1,39 @@
=== tests/cases/conformance/classes/classDeclarations/classAndInterfaceMerge.d.ts ===
interface C { }
>C : C
declare class C { }
>C : C
interface C { }
>C : C
interface C { }
>C : C
declare module M {
>M : typeof M
interface C1 { }
>C1 : C1
class C1 { }
>C1 : C1
interface C1 { }
>C1 : C1
interface C1 { }
>C1 : C1
export class C2 { }
>C2 : C2
}
declare module M {
>M : typeof M
export interface C2 { }
>C2 : C2
}

View File

@ -0,0 +1,44 @@
tests/cases/conformance/classes/classDeclarations/classAndInterfaceMergeConflictingMembers.ts(2,12): error TS2300: Duplicate identifier 'x'.
tests/cases/conformance/classes/classDeclarations/classAndInterfaceMergeConflictingMembers.ts(6,5): error TS2300: Duplicate identifier 'x'.
tests/cases/conformance/classes/classDeclarations/classAndInterfaceMergeConflictingMembers.ts(10,15): error TS2300: Duplicate identifier 'x'.
tests/cases/conformance/classes/classDeclarations/classAndInterfaceMergeConflictingMembers.ts(14,5): error TS2300: Duplicate identifier 'x'.
tests/cases/conformance/classes/classDeclarations/classAndInterfaceMergeConflictingMembers.ts(18,13): error TS2300: Duplicate identifier 'x'.
tests/cases/conformance/classes/classDeclarations/classAndInterfaceMergeConflictingMembers.ts(22,5): error TS2300: Duplicate identifier 'x'.
==== tests/cases/conformance/classes/classDeclarations/classAndInterfaceMergeConflictingMembers.ts (6 errors) ====
declare class C1 {
public x : number;
~
!!! error TS2300: Duplicate identifier 'x'.
}
interface C1 {
x : number;
~
!!! error TS2300: Duplicate identifier 'x'.
}
declare class C2 {
protected x : number;
~
!!! error TS2300: Duplicate identifier 'x'.
}
interface C2 {
x : number;
~
!!! error TS2300: Duplicate identifier 'x'.
}
declare class C3 {
private x : number;
~
!!! error TS2300: Duplicate identifier 'x'.
}
interface C3 {
x : number;
~
!!! error TS2300: Duplicate identifier 'x'.
}

View File

@ -0,0 +1,26 @@
//// [classAndInterfaceMergeConflictingMembers.ts]
declare class C1 {
public x : number;
}
interface C1 {
x : number;
}
declare class C2 {
protected x : number;
}
interface C2 {
x : number;
}
declare class C3 {
private x : number;
}
interface C3 {
x : number;
}
//// [classAndInterfaceMergeConflictingMembers.js]

View File

@ -1,27 +1,39 @@
tests/cases/conformance/classes/classDeclarations/classAndInterfaceWithSameName.ts(1,7): error TS2300: Duplicate identifier 'C'.
tests/cases/conformance/classes/classDeclarations/classAndInterfaceWithSameName.ts(2,11): error TS2300: Duplicate identifier 'C'.
tests/cases/conformance/classes/classDeclarations/classAndInterfaceWithSameName.ts(5,11): error TS2300: Duplicate identifier 'D'.
tests/cases/conformance/classes/classDeclarations/classAndInterfaceWithSameName.ts(9,15): error TS2300: Duplicate identifier 'D'.
tests/cases/conformance/classes/classDeclarations/classAndInterfaceWithSameName.ts(1,7): error TS2518: Only an ambient class can be merged with an interface.
tests/cases/conformance/classes/classDeclarations/classAndInterfaceWithSameName.ts(1,11): error TS2300: Duplicate identifier 'foo'.
tests/cases/conformance/classes/classDeclarations/classAndInterfaceWithSameName.ts(2,11): error TS2518: Only an ambient class can be merged with an interface.
tests/cases/conformance/classes/classDeclarations/classAndInterfaceWithSameName.ts(2,15): error TS2300: Duplicate identifier 'foo'.
tests/cases/conformance/classes/classDeclarations/classAndInterfaceWithSameName.ts(5,11): error TS2518: Only an ambient class can be merged with an interface.
tests/cases/conformance/classes/classDeclarations/classAndInterfaceWithSameName.ts(6,9): error TS2300: Duplicate identifier 'bar'.
tests/cases/conformance/classes/classDeclarations/classAndInterfaceWithSameName.ts(9,15): error TS2518: Only an ambient class can be merged with an interface.
tests/cases/conformance/classes/classDeclarations/classAndInterfaceWithSameName.ts(10,9): error TS2300: Duplicate identifier 'bar'.
==== tests/cases/conformance/classes/classDeclarations/classAndInterfaceWithSameName.ts (4 errors) ====
==== tests/cases/conformance/classes/classDeclarations/classAndInterfaceWithSameName.ts (8 errors) ====
class C { foo: string; }
~
!!! error TS2300: Duplicate identifier 'C'.
!!! error TS2518: Only an ambient class can be merged with an interface.
~~~
!!! error TS2300: Duplicate identifier 'foo'.
interface C { foo: string; } // error
~
!!! error TS2300: Duplicate identifier 'C'.
!!! error TS2518: Only an ambient class can be merged with an interface.
~~~
!!! error TS2300: Duplicate identifier 'foo'.
module M {
class D {
~
!!! error TS2300: Duplicate identifier 'D'.
!!! error TS2518: Only an ambient class can be merged with an interface.
bar: string;
~~~
!!! error TS2300: Duplicate identifier 'bar'.
}
interface D { // error
~
!!! error TS2300: Duplicate identifier 'D'.
!!! error TS2518: Only an ambient class can be merged with an interface.
bar: string;
~~~
!!! error TS2300: Duplicate identifier 'bar'.
}
}

View File

@ -0,0 +1,41 @@
tests/cases/conformance/classes/classDeclarations/classImplementsMergedClassInterface.ts(9,7): error TS2420: Class 'C2' incorrectly implements interface 'C1'.
Property 'x' is missing in type 'C2'.
tests/cases/conformance/classes/classDeclarations/classImplementsMergedClassInterface.ts(12,7): error TS2420: Class 'C3' incorrectly implements interface 'C1'.
Property 'y' is missing in type 'C3'.
tests/cases/conformance/classes/classDeclarations/classImplementsMergedClassInterface.ts(16,7): error TS2420: Class 'C4' incorrectly implements interface 'C1'.
Property 'x' is missing in type 'C4'.
==== tests/cases/conformance/classes/classDeclarations/classImplementsMergedClassInterface.ts (3 errors) ====
declare class C1 {
x : number;
}
interface C1 {
y : number;
}
class C2 implements C1 { // error -- missing x
~~
!!! error TS2420: Class 'C2' incorrectly implements interface 'C1'.
!!! error TS2420: Property 'x' is missing in type 'C2'.
}
class C3 implements C1 { // error -- missing y
~~
!!! error TS2420: Class 'C3' incorrectly implements interface 'C1'.
!!! error TS2420: Property 'y' is missing in type 'C3'.
x : number;
}
class C4 implements C1 { // error -- missing x
~~
!!! error TS2420: Class 'C4' incorrectly implements interface 'C1'.
!!! error TS2420: Property 'x' is missing in type 'C4'.
y : number;
}
class C5 implements C1 { // okay
x : number;
y : number;
}

View File

@ -0,0 +1,46 @@
//// [classImplementsMergedClassInterface.ts]
declare class C1 {
x : number;
}
interface C1 {
y : number;
}
class C2 implements C1 { // error -- missing x
}
class C3 implements C1 { // error -- missing y
x : number;
}
class C4 implements C1 { // error -- missing x
y : number;
}
class C5 implements C1 { // okay
x : number;
y : number;
}
//// [classImplementsMergedClassInterface.js]
var C2 = (function () {
function C2() {
}
return C2;
})();
var C3 = (function () {
function C3() {
}
return C3;
})();
var C4 = (function () {
function C4() {
}
return C4;
})();
var C5 = (function () {
function C5() {
}
return C5;
})();

View File

@ -1,50 +1,50 @@
tests/cases/compiler/clinterfaces.ts(2,11): error TS2300: Duplicate identifier 'C'.
tests/cases/compiler/clinterfaces.ts(3,15): error TS2300: Duplicate identifier 'C'.
tests/cases/compiler/clinterfaces.ts(4,15): error TS2300: Duplicate identifier 'D'.
tests/cases/compiler/clinterfaces.ts(5,11): error TS2300: Duplicate identifier 'D'.
tests/cases/compiler/clinterfaces.ts(8,11): error TS2300: Duplicate identifier 'Foo'.
tests/cases/compiler/clinterfaces.ts(12,7): error TS2300: Duplicate identifier 'Foo'.
tests/cases/compiler/clinterfaces.ts(16,7): error TS2300: Duplicate identifier 'Bar'.
tests/cases/compiler/clinterfaces.ts(20,11): error TS2300: Duplicate identifier 'Bar'.
tests/cases/compiler/clinterfaces.ts(2,11): error TS2518: Only an ambient class can be merged with an interface.
tests/cases/compiler/clinterfaces.ts(3,15): error TS2518: Only an ambient class can be merged with an interface.
tests/cases/compiler/clinterfaces.ts(4,15): error TS2518: Only an ambient class can be merged with an interface.
tests/cases/compiler/clinterfaces.ts(5,11): error TS2518: Only an ambient class can be merged with an interface.
tests/cases/compiler/clinterfaces.ts(8,11): error TS2518: Only an ambient class can be merged with an interface.
tests/cases/compiler/clinterfaces.ts(12,7): error TS2518: Only an ambient class can be merged with an interface.
tests/cases/compiler/clinterfaces.ts(16,7): error TS2518: Only an ambient class can be merged with an interface.
tests/cases/compiler/clinterfaces.ts(20,11): error TS2518: Only an ambient class can be merged with an interface.
==== tests/cases/compiler/clinterfaces.ts (8 errors) ====
module M {
class C { }
~
!!! error TS2300: Duplicate identifier 'C'.
!!! error TS2518: Only an ambient class can be merged with an interface.
interface C { }
~
!!! error TS2300: Duplicate identifier 'C'.
!!! error TS2518: Only an ambient class can be merged with an interface.
interface D { }
~
!!! error TS2300: Duplicate identifier 'D'.
!!! error TS2518: Only an ambient class can be merged with an interface.
class D { }
~
!!! error TS2300: Duplicate identifier 'D'.
!!! error TS2518: Only an ambient class can be merged with an interface.
}
interface Foo<T> {
~~~
!!! error TS2300: Duplicate identifier 'Foo'.
!!! error TS2518: Only an ambient class can be merged with an interface.
a: string;
}
class Foo<T>{
~~~
!!! error TS2300: Duplicate identifier 'Foo'.
!!! error TS2518: Only an ambient class can be merged with an interface.
b: number;
}
class Bar<T>{
~~~
!!! error TS2300: Duplicate identifier 'Bar'.
!!! error TS2518: Only an ambient class can be merged with an interface.
b: number;
}
interface Bar<T> {
~~~
!!! error TS2300: Duplicate identifier 'Bar'.
!!! error TS2518: Only an ambient class can be merged with an interface.
a: string;
}

View File

@ -49,3 +49,4 @@ var Bar = (function () {
}
return Bar;
})();
module.exports = Foo;

View File

@ -1,17 +1,17 @@
tests/cases/compiler/declInput.ts(1,11): error TS2300: Duplicate identifier 'bar'.
tests/cases/compiler/declInput.ts(5,7): error TS2300: Duplicate identifier 'bar'.
tests/cases/compiler/declInput.ts(1,11): error TS2518: Only an ambient class can be merged with an interface.
tests/cases/compiler/declInput.ts(5,7): error TS2518: Only an ambient class can be merged with an interface.
==== tests/cases/compiler/declInput.ts (2 errors) ====
interface bar {
~~~
!!! error TS2300: Duplicate identifier 'bar'.
!!! error TS2518: Only an ambient class can be merged with an interface.
}
class bar {
~~~
!!! error TS2300: Duplicate identifier 'bar'.
!!! error TS2518: Only an ambient class can be merged with an interface.
public f() { return ''; }
public g() { return {a: <bar>null, b: undefined, c: void 4 }; }
public h(x = 4, y = null, z = '') { x++; }

View File

@ -0,0 +1,43 @@
tests/cases/conformance/classes/classDeclarations/file1.ts(3,15): error TS2300: Duplicate identifier 'C1'.
tests/cases/conformance/classes/classDeclarations/file1.ts(5,15): error TS2300: Duplicate identifier 'C1'.
tests/cases/conformance/classes/classDeclarations/file1.ts(7,15): error TS2300: Duplicate identifier 'C2'.
tests/cases/conformance/classes/classDeclarations/file1.ts(9,11): error TS2300: Duplicate identifier 'C2'.
tests/cases/conformance/classes/classDeclarations/file1.ts(11,15): error TS2300: Duplicate identifier 'C2'.
tests/cases/conformance/classes/classDeclarations/file2.ts(2,15): error TS2300: Duplicate identifier 'C3'.
tests/cases/conformance/classes/classDeclarations/file3.ts(2,15): error TS2300: Duplicate identifier 'C3'.
==== tests/cases/conformance/classes/classDeclarations/file1.ts (5 errors) ====
declare class C1 {}
~~
!!! error TS2300: Duplicate identifier 'C1'.
declare class C1 {}
~~
!!! error TS2300: Duplicate identifier 'C1'.
declare class C2 {}
~~
!!! error TS2300: Duplicate identifier 'C2'.
interface C2 {}
~~
!!! error TS2300: Duplicate identifier 'C2'.
declare class C2 {}
~~
!!! error TS2300: Duplicate identifier 'C2'.
==== tests/cases/conformance/classes/classDeclarations/file2.ts (1 errors) ====
declare class C3 { }
~~
!!! error TS2300: Duplicate identifier 'C3'.
==== tests/cases/conformance/classes/classDeclarations/file3.ts (1 errors) ====
declare class C3 { }
~~
!!! error TS2300: Duplicate identifier 'C3'.

View File

@ -0,0 +1,26 @@
//// [tests/cases/conformance/classes/classDeclarations/declaredClassMergedwithSelf.ts] ////
//// [file1.ts]
declare class C1 {}
declare class C1 {}
declare class C2 {}
interface C2 {}
declare class C2 {}
//// [file2.ts]
declare class C3 { }
//// [file3.ts]
declare class C3 { }
//// [file1.js]
//// [file2.js]
//// [file3.js]

View File

@ -1,5 +1,5 @@
tests/cases/compiler/duplicateIdentifiersAcrossContainerBoundaries.ts(2,22): error TS2300: Duplicate identifier 'I'.
tests/cases/compiler/duplicateIdentifiersAcrossContainerBoundaries.ts(5,18): error TS2300: Duplicate identifier 'I'.
tests/cases/compiler/duplicateIdentifiersAcrossContainerBoundaries.ts(2,22): error TS2518: Only an ambient class can be merged with an interface.
tests/cases/compiler/duplicateIdentifiersAcrossContainerBoundaries.ts(5,18): error TS2518: Only an ambient class can be merged with an interface.
tests/cases/compiler/duplicateIdentifiersAcrossContainerBoundaries.ts(9,21): error TS2300: Duplicate identifier 'f'.
tests/cases/compiler/duplicateIdentifiersAcrossContainerBoundaries.ts(12,18): error TS2300: Duplicate identifier 'f'.
tests/cases/compiler/duplicateIdentifiersAcrossContainerBoundaries.ts(37,12): error TS2300: Duplicate identifier 'x'.
@ -10,12 +10,12 @@ tests/cases/compiler/duplicateIdentifiersAcrossContainerBoundaries.ts(41,16): er
module M {
export interface I { }
~
!!! error TS2300: Duplicate identifier 'I'.
!!! error TS2518: Only an ambient class can be merged with an interface.
}
module M {
export class I { } // error
~
!!! error TS2300: Duplicate identifier 'I'.
!!! error TS2518: Only an ambient class can be merged with an interface.
}
module M {

View File

@ -0,0 +1,68 @@
tests/cases/compiler/file1.ts(2,11): error TS2518: Only an ambient class can be merged with an interface.
tests/cases/compiler/file1.ts(3,7): error TS2518: Only an ambient class can be merged with an interface.
tests/cases/compiler/file1.ts(4,7): error TS2300: Duplicate identifier 'C2'.
tests/cases/compiler/file1.ts(5,10): error TS2300: Duplicate identifier 'f'.
tests/cases/compiler/file1.ts(9,12): error TS2300: Duplicate identifier 'x'.
tests/cases/compiler/file2.ts(1,7): error TS2518: Only an ambient class can be merged with an interface.
tests/cases/compiler/file2.ts(2,11): error TS2518: Only an ambient class can be merged with an interface.
tests/cases/compiler/file2.ts(3,10): error TS2300: Duplicate identifier 'C2'.
tests/cases/compiler/file2.ts(4,7): error TS2300: Duplicate identifier 'f'.
tests/cases/compiler/file2.ts(7,8): error TS2433: A namespace declaration cannot be in a different file from a class or function with which it is merged
tests/cases/compiler/file2.ts(8,16): error TS2300: Duplicate identifier 'x'.
==== tests/cases/compiler/file1.ts (5 errors) ====
interface I { }
~
!!! error TS2518: Only an ambient class can be merged with an interface.
class C1 { }
~~
!!! error TS2518: Only an ambient class can be merged with an interface.
class C2 { }
~~
!!! error TS2300: Duplicate identifier 'C2'.
function f() { }
~
!!! error TS2300: Duplicate identifier 'f'.
var v = 3;
class Foo {
static x: number;
~
!!! error TS2300: Duplicate identifier 'x'.
}
module N {
export module F {
var t;
}
}
==== tests/cases/compiler/file2.ts (6 errors) ====
class I { } // error -- cannot merge interface with non-ambient class
~
!!! error TS2518: Only an ambient class can be merged with an interface.
interface C1 { } // error -- cannot merge interface with non-ambient class
~~
!!! error TS2518: Only an ambient class can be merged with an interface.
function C2() { } // error -- cannot merge function with non-ambient class
~~
!!! error TS2300: Duplicate identifier 'C2'.
class f { } // error -- cannot merge function with non-ambient class
~
!!! error TS2300: Duplicate identifier 'f'.
var v = 3;
module Foo {
~~~
!!! error TS2433: A namespace declaration cannot be in a different file from a class or function with which it is merged
export var x: number; // error for redeclaring var in a different parent
~
!!! error TS2300: Duplicate identifier 'x'.
}
declare module N {
export function F(); // no error because function is ambient
}

View File

@ -0,0 +1,110 @@
//// [tests/cases/compiler/duplicateIdentifiersAcrossFileBoundaries.ts] ////
//// [file1.ts]
interface I { }
class C1 { }
class C2 { }
function f() { }
var v = 3;
class Foo {
static x: number;
}
module N {
export module F {
var t;
}
}
//// [file2.ts]
class I { } // error -- cannot merge interface with non-ambient class
interface C1 { } // error -- cannot merge interface with non-ambient class
function C2() { } // error -- cannot merge function with non-ambient class
class f { } // error -- cannot merge function with non-ambient class
var v = 3;
module Foo {
export var x: number; // error for redeclaring var in a different parent
}
declare module N {
export function F(); // no error because function is ambient
}
//// [file1.js]
var C1 = (function () {
function C1() {
}
return C1;
})();
var C2 = (function () {
function C2() {
}
return C2;
})();
function f() { }
var v = 3;
var Foo = (function () {
function Foo() {
}
return Foo;
})();
var N;
(function (N) {
var F;
(function (F) {
var t;
})(F = N.F || (N.F = {}));
})(N || (N = {}));
//// [file2.js]
var I = (function () {
function I() {
}
return I;
})(); // error -- cannot merge interface with non-ambient class
function C2() { } // error -- cannot merge function with non-ambient class
var f = (function () {
function f() {
}
return f;
})(); // error -- cannot merge function with non-ambient class
var v = 3;
var Foo;
(function (Foo) {
})(Foo || (Foo = {}));
//// [file1.d.ts]
interface I {
}
declare class C1 {
}
declare class C2 {
}
declare function f(): void;
declare var v: number;
declare class Foo {
static x: number;
}
declare module N {
module F {
}
}
//// [file2.d.ts]
declare class I {
}
interface C1 {
}
declare function C2(): void;
declare class f {
}
declare var v: number;
declare module Foo {
var x: number;
}
declare module N {
function F(): any;
}

View File

@ -1,5 +1,5 @@
tests/cases/compiler/interfaceDeclaration2.ts(4,11): error TS2300: Duplicate identifier 'I2'.
tests/cases/compiler/interfaceDeclaration2.ts(5,7): error TS2300: Duplicate identifier 'I2'.
tests/cases/compiler/interfaceDeclaration2.ts(4,11): error TS2518: Only an ambient class can be merged with an interface.
tests/cases/compiler/interfaceDeclaration2.ts(5,7): error TS2518: Only an ambient class can be merged with an interface.
==== tests/cases/compiler/interfaceDeclaration2.ts (2 errors) ====
@ -8,10 +8,10 @@ tests/cases/compiler/interfaceDeclaration2.ts(5,7): error TS2300: Duplicate iden
interface I2 { }
~~
!!! error TS2300: Duplicate identifier 'I2'.
!!! error TS2518: Only an ambient class can be merged with an interface.
class I2 { }
~~
!!! error TS2300: Duplicate identifier 'I2'.
!!! error TS2518: Only an ambient class can be merged with an interface.
interface I3 { }
function I3() { }

View File

@ -0,0 +1,19 @@
//// [mergeClassInterfaceAndModule.ts]
interface C1 {}
declare class C1 {}
module C1 {}
declare class C2 {}
interface C2 {}
module C2 {}
declare class C3 {}
module C3 {}
interface C3 {}
module C4 {}
declare class C4 {} // error -- class declaration must preceed module declaration
interface C4 {}
//// [mergeClassInterfaceAndModule.js]

View File

@ -0,0 +1,38 @@
=== tests/cases/conformance/classes/classDeclarations/mergeClassInterfaceAndModule.ts ===
interface C1 {}
>C1 : Symbol(C1, Decl(mergeClassInterfaceAndModule.ts, 0, 0), Decl(mergeClassInterfaceAndModule.ts, 1, 15), Decl(mergeClassInterfaceAndModule.ts, 2, 19))
declare class C1 {}
>C1 : Symbol(C1, Decl(mergeClassInterfaceAndModule.ts, 0, 0), Decl(mergeClassInterfaceAndModule.ts, 1, 15), Decl(mergeClassInterfaceAndModule.ts, 2, 19))
module C1 {}
>C1 : Symbol(C1, Decl(mergeClassInterfaceAndModule.ts, 0, 0), Decl(mergeClassInterfaceAndModule.ts, 1, 15), Decl(mergeClassInterfaceAndModule.ts, 2, 19))
declare class C2 {}
>C2 : Symbol(C2, Decl(mergeClassInterfaceAndModule.ts, 3, 12), Decl(mergeClassInterfaceAndModule.ts, 5, 19), Decl(mergeClassInterfaceAndModule.ts, 6, 15))
interface C2 {}
>C2 : Symbol(C2, Decl(mergeClassInterfaceAndModule.ts, 3, 12), Decl(mergeClassInterfaceAndModule.ts, 5, 19), Decl(mergeClassInterfaceAndModule.ts, 6, 15))
module C2 {}
>C2 : Symbol(C2, Decl(mergeClassInterfaceAndModule.ts, 3, 12), Decl(mergeClassInterfaceAndModule.ts, 5, 19), Decl(mergeClassInterfaceAndModule.ts, 6, 15))
declare class C3 {}
>C3 : Symbol(C3, Decl(mergeClassInterfaceAndModule.ts, 7, 12), Decl(mergeClassInterfaceAndModule.ts, 9, 19), Decl(mergeClassInterfaceAndModule.ts, 10, 12))
module C3 {}
>C3 : Symbol(C3, Decl(mergeClassInterfaceAndModule.ts, 7, 12), Decl(mergeClassInterfaceAndModule.ts, 9, 19), Decl(mergeClassInterfaceAndModule.ts, 10, 12))
interface C3 {}
>C3 : Symbol(C3, Decl(mergeClassInterfaceAndModule.ts, 7, 12), Decl(mergeClassInterfaceAndModule.ts, 9, 19), Decl(mergeClassInterfaceAndModule.ts, 10, 12))
module C4 {}
>C4 : Symbol(C4, Decl(mergeClassInterfaceAndModule.ts, 11, 15), Decl(mergeClassInterfaceAndModule.ts, 13, 12), Decl(mergeClassInterfaceAndModule.ts, 14, 19))
declare class C4 {} // error -- class declaration must preceed module declaration
>C4 : Symbol(C4, Decl(mergeClassInterfaceAndModule.ts, 11, 15), Decl(mergeClassInterfaceAndModule.ts, 13, 12), Decl(mergeClassInterfaceAndModule.ts, 14, 19))
interface C4 {}
>C4 : Symbol(C4, Decl(mergeClassInterfaceAndModule.ts, 11, 15), Decl(mergeClassInterfaceAndModule.ts, 13, 12), Decl(mergeClassInterfaceAndModule.ts, 14, 19))

View File

@ -0,0 +1,38 @@
=== tests/cases/conformance/classes/classDeclarations/mergeClassInterfaceAndModule.ts ===
interface C1 {}
>C1 : C1
declare class C1 {}
>C1 : C1
module C1 {}
>C1 : typeof C1
declare class C2 {}
>C2 : C2
interface C2 {}
>C2 : C2
module C2 {}
>C2 : typeof C2
declare class C3 {}
>C3 : C3
module C3 {}
>C3 : typeof C3
interface C3 {}
>C3 : C3
module C4 {}
>C4 : typeof C4
declare class C4 {} // error -- class declaration must preceed module declaration
>C4 : C4
interface C4 {}
>C4 : C4

View File

@ -0,0 +1,67 @@
tests/cases/conformance/classes/classDeclarations/file1.ts(11,7): error TS2518: Only an ambient class can be merged with an interface.
tests/cases/conformance/classes/classDeclarations/file1.ts(13,11): error TS2518: Only an ambient class can be merged with an interface.
tests/cases/conformance/classes/classDeclarations/file1.ts(15,11): error TS2518: Only an ambient class can be merged with an interface.
tests/cases/conformance/classes/classDeclarations/file1.ts(17,7): error TS2518: Only an ambient class can be merged with an interface.
==== tests/cases/conformance/classes/classDeclarations/file1.ts (4 errors) ====
declare class C1 { }
interface C1 { }
interface C2 { }
declare class C2 { }
class C3 { } // error -- cannot merge non-ambient class and interface
~~
!!! error TS2518: Only an ambient class can be merged with an interface.
interface C3 { } // error -- cannot merge non-ambient class and interface
~~
!!! error TS2518: Only an ambient class can be merged with an interface.
interface C4 { } // error -- cannot merge non-ambient class and interface
~~
!!! error TS2518: Only an ambient class can be merged with an interface.
class C4 { } // error -- cannot merge non-ambient class and interface
~~
!!! error TS2518: Only an ambient class can be merged with an interface.
interface C5 {
x1: number;
}
declare class C5 {
x2: number;
}
interface C5 {
x3: number;
}
interface C5 {
x4: number;
}
// checks if properties actually were merged
var c5 : C5;
c5.x1;
c5.x2;
c5.x3;
c5.x4;
==== tests/cases/conformance/classes/classDeclarations/file2.ts (0 errors) ====
declare class C6 { }
interface C7 { }
==== tests/cases/conformance/classes/classDeclarations/file3.ts (0 errors) ====
interface C6 { }
declare class C7 { }

View File

@ -0,0 +1,117 @@
//// [tests/cases/conformance/classes/classDeclarations/mergedClassInterface.ts] ////
//// [file1.ts]
declare class C1 { }
interface C1 { }
interface C2 { }
declare class C2 { }
class C3 { } // error -- cannot merge non-ambient class and interface
interface C3 { } // error -- cannot merge non-ambient class and interface
interface C4 { } // error -- cannot merge non-ambient class and interface
class C4 { } // error -- cannot merge non-ambient class and interface
interface C5 {
x1: number;
}
declare class C5 {
x2: number;
}
interface C5 {
x3: number;
}
interface C5 {
x4: number;
}
// checks if properties actually were merged
var c5 : C5;
c5.x1;
c5.x2;
c5.x3;
c5.x4;
//// [file2.ts]
declare class C6 { }
interface C7 { }
//// [file3.ts]
interface C6 { }
declare class C7 { }
//// [file1.js]
var C3 = (function () {
function C3() {
}
return C3;
})(); // error -- cannot merge non-ambient class and interface
var C4 = (function () {
function C4() {
}
return C4;
})(); // error -- cannot merge non-ambient class and interface
// checks if properties actually were merged
var c5;
c5.x1;
c5.x2;
c5.x3;
c5.x4;
//// [file2.js]
//// [file3.js]
//// [file1.d.ts]
declare class C1 {
}
interface C1 {
}
interface C2 {
}
declare class C2 {
}
declare class C3 {
}
interface C3 {
}
interface C4 {
}
declare class C4 {
}
interface C5 {
x1: number;
}
declare class C5 {
x2: number;
}
interface C5 {
x3: number;
}
interface C5 {
x4: number;
}
declare var c5: C5;
//// [file2.d.ts]
declare class C6 {
}
interface C7 {
}
//// [file3.d.ts]
interface C6 {
}
declare class C7 {
}

View File

@ -11,10 +11,10 @@ tests/cases/compiler/nameCollisions.ts(33,11): error TS2300: Duplicate identifie
tests/cases/compiler/nameCollisions.ts(34,14): error TS2300: Duplicate identifier 'C'.
tests/cases/compiler/nameCollisions.ts(36,14): error TS2300: Duplicate identifier 'C2'.
tests/cases/compiler/nameCollisions.ts(37,11): error TS2300: Duplicate identifier 'C2'.
tests/cases/compiler/nameCollisions.ts(42,11): error TS2300: Duplicate identifier 'cli'.
tests/cases/compiler/nameCollisions.ts(43,15): error TS2300: Duplicate identifier 'cli'.
tests/cases/compiler/nameCollisions.ts(45,15): error TS2300: Duplicate identifier 'cli2'.
tests/cases/compiler/nameCollisions.ts(46,11): error TS2300: Duplicate identifier 'cli2'.
tests/cases/compiler/nameCollisions.ts(42,11): error TS2518: Only an ambient class can be merged with an interface.
tests/cases/compiler/nameCollisions.ts(43,15): error TS2518: Only an ambient class can be merged with an interface.
tests/cases/compiler/nameCollisions.ts(45,15): error TS2518: Only an ambient class can be merged with an interface.
tests/cases/compiler/nameCollisions.ts(46,11): error TS2518: Only an ambient class can be merged with an interface.
==== tests/cases/compiler/nameCollisions.ts (17 errors) ====
@ -87,15 +87,15 @@ tests/cases/compiler/nameCollisions.ts(46,11): error TS2300: Duplicate identifie
class cli { }
~~~
!!! error TS2300: Duplicate identifier 'cli'.
!!! error TS2518: Only an ambient class can be merged with an interface.
interface cli { } // error
~~~
!!! error TS2300: Duplicate identifier 'cli'.
!!! error TS2518: Only an ambient class can be merged with an interface.
interface cli2 { }
~~~~
!!! error TS2300: Duplicate identifier 'cli2'.
!!! error TS2518: Only an ambient class can be merged with an interface.
class cli2 { } // error
~~~~
!!! error TS2300: Duplicate identifier 'cli2'.
!!! error TS2518: Only an ambient class can be merged with an interface.
}

View File

@ -1,14 +1,13 @@
lib.d.ts(521,11): error TS2300: Duplicate identifier 'TemplateStringsArray'.
tests/cases/compiler/templateStringsArrayTypeDefinedInES5Mode.ts(2,7): error TS2300: Duplicate identifier 'TemplateStringsArray'.
tests/cases/compiler/templateStringsArrayTypeDefinedInES5Mode.ts(8,3): error TS2345: Argument of type '{ [x: number]: undefined; }' is not assignable to parameter of type 'TemplateStringsArray'.
Property 'raw' is missing in type '{ [x: number]: undefined; }'.
tests/cases/compiler/templateStringsArrayTypeDefinedInES5Mode.ts(2,7): error TS2518: Only an ambient class can be merged with an interface.
tests/cases/compiler/templateStringsArrayTypeDefinedInES5Mode.ts(8,3): error TS2345: Argument of type '{}' is not assignable to parameter of type 'TemplateStringsArray'.
Property 'raw' is missing in type '{}'.
==== tests/cases/compiler/templateStringsArrayTypeDefinedInES5Mode.ts (2 errors) ====
class TemplateStringsArray {
~~~~~~~~~~~~~~~~~~~~
!!! error TS2300: Duplicate identifier 'TemplateStringsArray'.
!!! error TS2518: Only an ambient class can be merged with an interface.
}
function f(x: TemplateStringsArray, y: number, z: number) {
@ -16,7 +15,7 @@ tests/cases/compiler/templateStringsArrayTypeDefinedInES5Mode.ts(8,3): error TS2
f({}, 10, 10);
~~
!!! error TS2345: Argument of type '{ [x: number]: undefined; }' is not assignable to parameter of type 'TemplateStringsArray'.
!!! error TS2345: Property 'raw' is missing in type '{ [x: number]: undefined; }'.
!!! error TS2345: Argument of type '{}' is not assignable to parameter of type 'TemplateStringsArray'.
!!! error TS2345: Property 'raw' is missing in type '{}'.
f `abcdef${ 1234 }${ 5678 }ghijkl`;

View File

@ -1,14 +1,13 @@
lib.d.ts(521,11): error TS2300: Duplicate identifier 'TemplateStringsArray'.
tests/cases/compiler/templateStringsArrayTypeRedefinedInES6Mode.ts(2,7): error TS2300: Duplicate identifier 'TemplateStringsArray'.
tests/cases/compiler/templateStringsArrayTypeRedefinedInES6Mode.ts(8,3): error TS2345: Argument of type '{ [x: number]: undefined; }' is not assignable to parameter of type 'TemplateStringsArray'.
Property 'raw' is missing in type '{ [x: number]: undefined; }'.
tests/cases/compiler/templateStringsArrayTypeRedefinedInES6Mode.ts(2,7): error TS2518: Only an ambient class can be merged with an interface.
tests/cases/compiler/templateStringsArrayTypeRedefinedInES6Mode.ts(8,3): error TS2345: Argument of type '{}' is not assignable to parameter of type 'TemplateStringsArray'.
Property 'raw' is missing in type '{}'.
==== tests/cases/compiler/templateStringsArrayTypeRedefinedInES6Mode.ts (2 errors) ====
class TemplateStringsArray {
~~~~~~~~~~~~~~~~~~~~
!!! error TS2300: Duplicate identifier 'TemplateStringsArray'.
!!! error TS2518: Only an ambient class can be merged with an interface.
}
function f(x: TemplateStringsArray, y: number, z: number) {
@ -16,7 +15,7 @@ tests/cases/compiler/templateStringsArrayTypeRedefinedInES6Mode.ts(8,3): error T
f({}, 10, 10);
~~
!!! error TS2345: Argument of type '{ [x: number]: undefined; }' is not assignable to parameter of type 'TemplateStringsArray'.
!!! error TS2345: Property 'raw' is missing in type '{ [x: number]: undefined; }'.
!!! error TS2345: Argument of type '{}' is not assignable to parameter of type 'TemplateStringsArray'.
!!! error TS2345: Property 'raw' is missing in type '{}'.
f `abcdef${ 1234 }${ 5678 }ghijkl`;

View File

@ -1,2 +0,0 @@
interface foo{ } // error
class foo{ } // error

View File

@ -1,2 +0,0 @@
class cli { } // error
interface cli { } // error

View File

@ -0,0 +1,33 @@
// @declaration: true
// @Filename: file1.ts
interface I { }
class C1 { }
class C2 { }
function f() { }
var v = 3;
class Foo {
static x: number;
}
module N {
export module F {
var t;
}
}
// @Filename: file2.ts
class I { } // error -- cannot merge interface with non-ambient class
interface C1 { } // error -- cannot merge interface with non-ambient class
function C2() { } // error -- cannot merge function with non-ambient class
class f { } // error -- cannot merge function with non-ambient class
var v = 3;
module Foo {
export var x: number; // error for redeclaring var in a different parent
}
declare module N {
export function F(); // no error because function is ambient
}

View File

@ -16,9 +16,25 @@ class CC1 {}
class CC2 {}
abstract class CC2 {}
declare abstract class DCI {}
interface DCI {}
interface DIC {}
declare abstract class DIC {}
declare abstract class DCC1 {}
declare class DCC1 {}
declare class DCC2 {}
declare abstract class DCC2 {}
new CM;
new MC;
new CI;
new IC;
new CC1;
new CC2;
new CC2;
new DCI;
new DIC;
new DCC1;
new DCC2;

View File

@ -0,0 +1,25 @@
interface C { }
declare class C { }
interface C { }
interface C { }
declare module M {
interface C1 { }
class C1 { }
interface C1 { }
interface C1 { }
export class C2 { }
}
declare module M {
export interface C2 { }
}

View File

@ -0,0 +1,23 @@
declare class C1 {
public x : number;
}
interface C1 {
x : number;
}
declare class C2 {
protected x : number;
}
interface C2 {
x : number;
}
declare class C3 {
private x : number;
}
interface C3 {
x : number;
}

View File

@ -0,0 +1,23 @@
declare class C1 {
x : number;
}
interface C1 {
y : number;
}
class C2 implements C1 { // error -- missing x
}
class C3 implements C1 { // error -- missing y
x : number;
}
class C4 implements C1 { // error -- missing x
y : number;
}
class C5 implements C1 { // okay
x : number;
y : number;
}

View File

@ -0,0 +1,20 @@
// @Filename: file1.ts
declare class C1 {}
declare class C1 {}
declare class C2 {}
interface C2 {}
declare class C2 {}
// @Filename: file2.ts
declare class C3 { }
// @Filename: file3.ts
declare class C3 { }

View File

@ -0,0 +1,16 @@
interface C1 {}
declare class C1 {}
module C1 {}
declare class C2 {}
interface C2 {}
module C2 {}
declare class C3 {}
module C3 {}
interface C3 {}
module C4 {}
declare class C4 {} // error -- class declaration must preceed module declaration
interface C4 {}

View File

@ -0,0 +1,54 @@
// @declaration: true
// @Filename: file1.ts
declare class C1 { }
interface C1 { }
interface C2 { }
declare class C2 { }
class C3 { } // error -- cannot merge non-ambient class and interface
interface C3 { } // error -- cannot merge non-ambient class and interface
interface C4 { } // error -- cannot merge non-ambient class and interface
class C4 { } // error -- cannot merge non-ambient class and interface
interface C5 {
x1: number;
}
declare class C5 {
x2: number;
}
interface C5 {
x3: number;
}
interface C5 {
x4: number;
}
// checks if properties actually were merged
var c5 : C5;
c5.x1;
c5.x2;
c5.x3;
c5.x4;
// @Filename: file2.ts
declare class C6 { }
interface C7 { }
// @Filename: file3.ts
interface C6 { }
declare class C7 { }