diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index e403ed994e566..e30178e987bb0 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -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; diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index d72e74f748eb6..d07764045a57b 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -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) { diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 24b182c7134d8..a17f885759081 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -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." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 9b58e3143b2ee..94be4f53c9717 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -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 diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 7b683f2eeb5d0..4617ad98b0240 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -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), diff --git a/tests/baselines/reference/augmentedTypesClass2.errors.txt b/tests/baselines/reference/augmentedTypesClass2.errors.txt index 5881e49dae92d..278dca816fa30 100644 --- a/tests/baselines/reference/augmentedTypesClass2.errors.txt +++ b/tests/baselines/reference/augmentedTypesClass2.errors.txt @@ -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; } diff --git a/tests/baselines/reference/augmentedTypesInterface.errors.txt b/tests/baselines/reference/augmentedTypesInterface.errors.txt index a9fc28dd5ae57..690bf8b7a991c 100644 --- a/tests/baselines/reference/augmentedTypesInterface.errors.txt +++ b/tests/baselines/reference/augmentedTypesInterface.errors.txt @@ -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; } diff --git a/tests/baselines/reference/class1.errors.txt b/tests/baselines/reference/class1.errors.txt deleted file mode 100644 index b90fae9cb402e..0000000000000 --- a/tests/baselines/reference/class1.errors.txt +++ /dev/null @@ -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'. \ No newline at end of file diff --git a/tests/baselines/reference/class1.js b/tests/baselines/reference/class1.js deleted file mode 100644 index 7a104e237b6c0..0000000000000 --- a/tests/baselines/reference/class1.js +++ /dev/null @@ -1,10 +0,0 @@ -//// [class1.ts] -interface foo{ } // error -class foo{ } // error - -//// [class1.js] -var foo = (function () { - function foo() { - } - return foo; -})(); // error diff --git a/tests/baselines/reference/classAbstractMergedDeclaration.errors.txt b/tests/baselines/reference/classAbstractMergedDeclaration.errors.txt index ca2cc3b8c2d08..b3a2dec5e9c52 100644 --- a/tests/baselines/reference/classAbstractMergedDeclaration.errors.txt +++ b/tests/baselines/reference/classAbstractMergedDeclaration.errors.txt @@ -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; \ No newline at end of file + 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; \ No newline at end of file diff --git a/tests/baselines/reference/classAbstractMergedDeclaration.js b/tests/baselines/reference/classAbstractMergedDeclaration.js index 1b4d6fea342f0..f6a91f870d299 100644 --- a/tests/baselines/reference/classAbstractMergedDeclaration.js +++ b/tests/baselines/reference/classAbstractMergedDeclaration.js @@ -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; diff --git a/tests/baselines/reference/classAndInterface1.errors.txt b/tests/baselines/reference/classAndInterface1.errors.txt deleted file mode 100644 index 8d31e847d71e7..0000000000000 --- a/tests/baselines/reference/classAndInterface1.errors.txt +++ /dev/null @@ -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'. \ No newline at end of file diff --git a/tests/baselines/reference/classAndInterface1.js b/tests/baselines/reference/classAndInterface1.js deleted file mode 100644 index 5efabded83813..0000000000000 --- a/tests/baselines/reference/classAndInterface1.js +++ /dev/null @@ -1,10 +0,0 @@ -//// [classAndInterface1.ts] - class cli { } // error -interface cli { } // error - -//// [classAndInterface1.js] -var cli = (function () { - function cli() { - } - return cli; -})(); // error diff --git a/tests/baselines/reference/classAndInterfaceMerge.d.symbols b/tests/baselines/reference/classAndInterfaceMerge.d.symbols new file mode 100644 index 0000000000000..84fc2b129c145 --- /dev/null +++ b/tests/baselines/reference/classAndInterfaceMerge.d.symbols @@ -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)) +} diff --git a/tests/baselines/reference/classAndInterfaceMerge.d.types b/tests/baselines/reference/classAndInterfaceMerge.d.types new file mode 100644 index 0000000000000..baab121ca6ea6 --- /dev/null +++ b/tests/baselines/reference/classAndInterfaceMerge.d.types @@ -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 +} diff --git a/tests/baselines/reference/classAndInterfaceMergeConflictingMembers.errors.txt b/tests/baselines/reference/classAndInterfaceMergeConflictingMembers.errors.txt new file mode 100644 index 0000000000000..48e52faae1e78 --- /dev/null +++ b/tests/baselines/reference/classAndInterfaceMergeConflictingMembers.errors.txt @@ -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'. + } \ No newline at end of file diff --git a/tests/baselines/reference/classAndInterfaceMergeConflictingMembers.js b/tests/baselines/reference/classAndInterfaceMergeConflictingMembers.js new file mode 100644 index 0000000000000..07b425383f439 --- /dev/null +++ b/tests/baselines/reference/classAndInterfaceMergeConflictingMembers.js @@ -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] diff --git a/tests/baselines/reference/classAndInterfaceWithSameName.errors.txt b/tests/baselines/reference/classAndInterfaceWithSameName.errors.txt index aa3e687cf4d3f..332024b74fdf0 100644 --- a/tests/baselines/reference/classAndInterfaceWithSameName.errors.txt +++ b/tests/baselines/reference/classAndInterfaceWithSameName.errors.txt @@ -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'. } } \ No newline at end of file diff --git a/tests/baselines/reference/classImplementsMergedClassInterface.errors.txt b/tests/baselines/reference/classImplementsMergedClassInterface.errors.txt new file mode 100644 index 0000000000000..3e62e72be8422 --- /dev/null +++ b/tests/baselines/reference/classImplementsMergedClassInterface.errors.txt @@ -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; + } \ No newline at end of file diff --git a/tests/baselines/reference/classImplementsMergedClassInterface.js b/tests/baselines/reference/classImplementsMergedClassInterface.js new file mode 100644 index 0000000000000..64a0198cc1627 --- /dev/null +++ b/tests/baselines/reference/classImplementsMergedClassInterface.js @@ -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; +})(); diff --git a/tests/baselines/reference/clinterfaces.errors.txt b/tests/baselines/reference/clinterfaces.errors.txt index d5eab2c7994df..5960e6ae32b2e 100644 --- a/tests/baselines/reference/clinterfaces.errors.txt +++ b/tests/baselines/reference/clinterfaces.errors.txt @@ -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 { ~~~ -!!! error TS2300: Duplicate identifier 'Foo'. +!!! error TS2518: Only an ambient class can be merged with an interface. a: string; } class Foo{ ~~~ -!!! error TS2300: Duplicate identifier 'Foo'. +!!! error TS2518: Only an ambient class can be merged with an interface. b: number; } class Bar{ ~~~ -!!! error TS2300: Duplicate identifier 'Bar'. +!!! error TS2518: Only an ambient class can be merged with an interface. b: number; } interface Bar { ~~~ -!!! error TS2300: Duplicate identifier 'Bar'. +!!! error TS2518: Only an ambient class can be merged with an interface. a: string; } diff --git a/tests/baselines/reference/clinterfaces.js b/tests/baselines/reference/clinterfaces.js index 02ae73498697a..a55924227c9ef 100644 --- a/tests/baselines/reference/clinterfaces.js +++ b/tests/baselines/reference/clinterfaces.js @@ -49,3 +49,4 @@ var Bar = (function () { } return Bar; })(); +module.exports = Foo; diff --git a/tests/baselines/reference/declInput.errors.txt b/tests/baselines/reference/declInput.errors.txt index 8ec341ce15bb9..179db3598abb3 100644 --- a/tests/baselines/reference/declInput.errors.txt +++ b/tests/baselines/reference/declInput.errors.txt @@ -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: null, b: undefined, c: void 4 }; } public h(x = 4, y = null, z = '') { x++; } diff --git a/tests/baselines/reference/declaredClassMergedwithSelf.errors.txt b/tests/baselines/reference/declaredClassMergedwithSelf.errors.txt new file mode 100644 index 0000000000000..a46dfb0d3394a --- /dev/null +++ b/tests/baselines/reference/declaredClassMergedwithSelf.errors.txt @@ -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'. \ No newline at end of file diff --git a/tests/baselines/reference/declaredClassMergedwithSelf.js b/tests/baselines/reference/declaredClassMergedwithSelf.js new file mode 100644 index 0000000000000..a38391d90dbc8 --- /dev/null +++ b/tests/baselines/reference/declaredClassMergedwithSelf.js @@ -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] diff --git a/tests/baselines/reference/duplicateIdentifiersAcrossContainerBoundaries.errors.txt b/tests/baselines/reference/duplicateIdentifiersAcrossContainerBoundaries.errors.txt index 6c80d13b2f44a..731e97482035a 100644 --- a/tests/baselines/reference/duplicateIdentifiersAcrossContainerBoundaries.errors.txt +++ b/tests/baselines/reference/duplicateIdentifiersAcrossContainerBoundaries.errors.txt @@ -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 { diff --git a/tests/baselines/reference/duplicateIdentifiersAcrossFileBoundaries.errors.txt b/tests/baselines/reference/duplicateIdentifiersAcrossFileBoundaries.errors.txt new file mode 100644 index 0000000000000..9867441f7700f --- /dev/null +++ b/tests/baselines/reference/duplicateIdentifiersAcrossFileBoundaries.errors.txt @@ -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 + } + \ No newline at end of file diff --git a/tests/baselines/reference/duplicateIdentifiersAcrossFileBoundaries.js b/tests/baselines/reference/duplicateIdentifiersAcrossFileBoundaries.js new file mode 100644 index 0000000000000..a2509ea97f462 --- /dev/null +++ b/tests/baselines/reference/duplicateIdentifiersAcrossFileBoundaries.js @@ -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; +} diff --git a/tests/baselines/reference/interfaceDeclaration2.errors.txt b/tests/baselines/reference/interfaceDeclaration2.errors.txt index 9739d946bc52b..db525e6f21f25 100644 --- a/tests/baselines/reference/interfaceDeclaration2.errors.txt +++ b/tests/baselines/reference/interfaceDeclaration2.errors.txt @@ -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() { } diff --git a/tests/baselines/reference/mergeClassInterfaceAndModule.js b/tests/baselines/reference/mergeClassInterfaceAndModule.js new file mode 100644 index 0000000000000..5b7315031cd21 --- /dev/null +++ b/tests/baselines/reference/mergeClassInterfaceAndModule.js @@ -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] diff --git a/tests/baselines/reference/mergeClassInterfaceAndModule.symbols b/tests/baselines/reference/mergeClassInterfaceAndModule.symbols new file mode 100644 index 0000000000000..a10227ed4618b --- /dev/null +++ b/tests/baselines/reference/mergeClassInterfaceAndModule.symbols @@ -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)) + diff --git a/tests/baselines/reference/mergeClassInterfaceAndModule.types b/tests/baselines/reference/mergeClassInterfaceAndModule.types new file mode 100644 index 0000000000000..a91691e5bacda --- /dev/null +++ b/tests/baselines/reference/mergeClassInterfaceAndModule.types @@ -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 + diff --git a/tests/baselines/reference/mergedClassInterface.errors.txt b/tests/baselines/reference/mergedClassInterface.errors.txt new file mode 100644 index 0000000000000..5b23b046db75c --- /dev/null +++ b/tests/baselines/reference/mergedClassInterface.errors.txt @@ -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 { } \ No newline at end of file diff --git a/tests/baselines/reference/mergedClassInterface.js b/tests/baselines/reference/mergedClassInterface.js new file mode 100644 index 0000000000000..7176255655dbf --- /dev/null +++ b/tests/baselines/reference/mergedClassInterface.js @@ -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 { +} diff --git a/tests/baselines/reference/nameCollisions.errors.txt b/tests/baselines/reference/nameCollisions.errors.txt index 5eb7ea2cf8023..5c32d4640705f 100644 --- a/tests/baselines/reference/nameCollisions.errors.txt +++ b/tests/baselines/reference/nameCollisions.errors.txt @@ -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. } \ No newline at end of file diff --git a/tests/baselines/reference/templateStringsArrayTypeDefinedInES5Mode.errors.txt b/tests/baselines/reference/templateStringsArrayTypeDefinedInES5Mode.errors.txt index 7c796d4739869..69d686c31561a 100644 --- a/tests/baselines/reference/templateStringsArrayTypeDefinedInES5Mode.errors.txt +++ b/tests/baselines/reference/templateStringsArrayTypeDefinedInES5Mode.errors.txt @@ -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`; \ No newline at end of file diff --git a/tests/baselines/reference/templateStringsArrayTypeRedefinedInES6Mode.errors.txt b/tests/baselines/reference/templateStringsArrayTypeRedefinedInES6Mode.errors.txt index 4b9cb63d9aaeb..02ccd7f2413f8 100644 --- a/tests/baselines/reference/templateStringsArrayTypeRedefinedInES6Mode.errors.txt +++ b/tests/baselines/reference/templateStringsArrayTypeRedefinedInES6Mode.errors.txt @@ -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`; \ No newline at end of file diff --git a/tests/cases/compiler/class1.ts b/tests/cases/compiler/class1.ts deleted file mode 100644 index c7b2115b88b28..0000000000000 --- a/tests/cases/compiler/class1.ts +++ /dev/null @@ -1,2 +0,0 @@ -interface foo{ } // error -class foo{ } // error \ No newline at end of file diff --git a/tests/cases/compiler/classAndInterface1.ts b/tests/cases/compiler/classAndInterface1.ts deleted file mode 100644 index 79b029158572e..0000000000000 --- a/tests/cases/compiler/classAndInterface1.ts +++ /dev/null @@ -1,2 +0,0 @@ - class cli { } // error -interface cli { } // error \ No newline at end of file diff --git a/tests/cases/compiler/duplicateIdentifiersAcrossFileBoundaries.ts b/tests/cases/compiler/duplicateIdentifiersAcrossFileBoundaries.ts new file mode 100644 index 0000000000000..94e5cd94ab188 --- /dev/null +++ b/tests/cases/compiler/duplicateIdentifiersAcrossFileBoundaries.ts @@ -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 +} diff --git a/tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractMergedDeclaration.ts b/tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractMergedDeclaration.ts index 160c0de298bb3..6e5686feb2562 100644 --- a/tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractMergedDeclaration.ts +++ b/tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractMergedDeclaration.ts @@ -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; \ No newline at end of file +new CC2; +new DCI; +new DIC; +new DCC1; +new DCC2; \ No newline at end of file diff --git a/tests/cases/conformance/classes/classDeclarations/classAndInterfaceMerge.d.ts b/tests/cases/conformance/classes/classDeclarations/classAndInterfaceMerge.d.ts new file mode 100644 index 0000000000000..1ef7724f81d30 --- /dev/null +++ b/tests/cases/conformance/classes/classDeclarations/classAndInterfaceMerge.d.ts @@ -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 { } +} \ No newline at end of file diff --git a/tests/cases/conformance/classes/classDeclarations/classAndInterfaceMergeConflictingMembers.ts b/tests/cases/conformance/classes/classDeclarations/classAndInterfaceMergeConflictingMembers.ts new file mode 100644 index 0000000000000..d11d67c3feabb --- /dev/null +++ b/tests/cases/conformance/classes/classDeclarations/classAndInterfaceMergeConflictingMembers.ts @@ -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; +} \ No newline at end of file diff --git a/tests/cases/conformance/classes/classDeclarations/classImplementsMergedClassInterface.ts b/tests/cases/conformance/classes/classDeclarations/classImplementsMergedClassInterface.ts new file mode 100644 index 0000000000000..d5ac1b005bfd3 --- /dev/null +++ b/tests/cases/conformance/classes/classDeclarations/classImplementsMergedClassInterface.ts @@ -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; +} \ No newline at end of file diff --git a/tests/cases/conformance/classes/classDeclarations/declaredClassMergedwithSelf.ts b/tests/cases/conformance/classes/classDeclarations/declaredClassMergedwithSelf.ts new file mode 100644 index 0000000000000..7445104e22833 --- /dev/null +++ b/tests/cases/conformance/classes/classDeclarations/declaredClassMergedwithSelf.ts @@ -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 { } \ No newline at end of file diff --git a/tests/cases/conformance/classes/classDeclarations/mergeClassInterfaceAndModule.ts b/tests/cases/conformance/classes/classDeclarations/mergeClassInterfaceAndModule.ts new file mode 100644 index 0000000000000..4dc733d28c05f --- /dev/null +++ b/tests/cases/conformance/classes/classDeclarations/mergeClassInterfaceAndModule.ts @@ -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 {} \ No newline at end of file diff --git a/tests/cases/conformance/classes/classDeclarations/mergedClassInterface.ts b/tests/cases/conformance/classes/classDeclarations/mergedClassInterface.ts new file mode 100644 index 0000000000000..29400c63808b8 --- /dev/null +++ b/tests/cases/conformance/classes/classDeclarations/mergedClassInterface.ts @@ -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 { } \ No newline at end of file