diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index eddddb5cb2b..dbce5f41ef4 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -14013,7 +14013,7 @@ namespace ts { } } - // Check each type parameter and check that list has no duplicate type parameter declarations + /** Check each type parameter and check that type parameters have no duplicate type parameter declarations */ function checkTypeParameters(typeParameterDeclarations: TypeParameterDeclaration[]) { if (typeParameterDeclarations) { for (let i = 0, n = typeParameterDeclarations.length; i < n; i++) { @@ -14031,6 +14031,24 @@ namespace ts { } } + /** Check that type parameter lists are identical across multiple declarations */ + function checkTypeParameterListsIdentical(node: ClassLikeDeclaration | InterfaceDeclaration, symbol: Symbol) { + if (symbol.declarations.length === 1) { + return; + } + let firstDecl: ClassLikeDeclaration | InterfaceDeclaration; + for (const declaration of symbol.declarations) { + if (declaration.kind === SyntaxKind.ClassDeclaration || declaration.kind === SyntaxKind.InterfaceDeclaration) { + if (!firstDecl) { + firstDecl = declaration; + } + else if (!areTypeParametersIdentical(firstDecl.typeParameters, node.typeParameters)) { + error(node.name, Diagnostics.All_declarations_of_0_must_have_identical_type_parameters, node.name.text); + } + } + } + } + function checkClassExpression(node: ClassExpression): Type { checkClassLikeDeclaration(node); checkNodeDeferred(node); @@ -14064,6 +14082,7 @@ namespace ts { const type = getDeclaredTypeOfSymbol(symbol); const typeWithThis = getTypeWithThisArgument(type); const staticType = getTypeOfSymbol(symbol); + checkTypeParameterListsIdentical(node, symbol); const baseTypeNode = getClassExtendsHeritageClauseElement(node); if (baseTypeNode) { @@ -14326,14 +14345,10 @@ namespace ts { checkExportsOnMergedDeclarations(node); const symbol = getSymbolOfNode(node); - const firstInterfaceDecl = getDeclarationOfKind(symbol, SyntaxKind.InterfaceDeclaration); - if (symbol.declarations.length > 1) { - if (node !== firstInterfaceDecl && !areTypeParametersIdentical(firstInterfaceDecl.typeParameters, node.typeParameters)) { - error(node.name, Diagnostics.All_declarations_of_an_interface_must_have_identical_type_parameters); - } - } + checkTypeParameterListsIdentical(node, symbol); // Only check this symbol once + const firstInterfaceDecl = getDeclarationOfKind(symbol, SyntaxKind.InterfaceDeclaration); if (node === firstInterfaceDecl) { const type = getDeclaredTypeOfSymbol(symbol); const typeWithThis = getTypeWithThisArgument(type); diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 16cf1911642..70c6d8ff167 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1311,7 +1311,7 @@ "category": "Error", "code": 2427 }, - "All declarations of an interface must have identical type parameters.": { + "All declarations of '{0}' must have identical type parameters.": { "category": "Error", "code": 2428 }, @@ -2801,4 +2801,4 @@ "category": "Error", "code": 17009 } -} +} diff --git a/tests/baselines/reference/constructSignaturesWithOverloads2.errors.txt b/tests/baselines/reference/constructSignaturesWithOverloads2.errors.txt index ceb828dd061..617f7b1502f 100644 --- a/tests/baselines/reference/constructSignaturesWithOverloads2.errors.txt +++ b/tests/baselines/reference/constructSignaturesWithOverloads2.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/types/objectTypeLiteral/constructSignatures/constructSignaturesWithOverloads2.ts(32,11): error TS2428: All declarations of an interface must have identical type parameters. +tests/cases/conformance/types/objectTypeLiteral/constructSignatures/constructSignaturesWithOverloads2.ts(32,11): error TS2428: All declarations of 'I' must have identical type parameters. ==== tests/cases/conformance/types/objectTypeLiteral/constructSignatures/constructSignaturesWithOverloads2.ts (1 errors) ==== @@ -35,7 +35,7 @@ tests/cases/conformance/types/objectTypeLiteral/constructSignatures/constructSig interface I { ~ -!!! error TS2428: All declarations of an interface must have identical type parameters. +!!! error TS2428: All declarations of 'I' must have identical type parameters. new (x: T, y?: number): C2; new (x: T, y: number): C2; } diff --git a/tests/baselines/reference/extendedInterfacesWithDuplicateTypeParameters.errors.txt b/tests/baselines/reference/extendedInterfacesWithDuplicateTypeParameters.errors.txt index 7d7fea1b2c6..7b47fee05af 100644 --- a/tests/baselines/reference/extendedInterfacesWithDuplicateTypeParameters.errors.txt +++ b/tests/baselines/reference/extendedInterfacesWithDuplicateTypeParameters.errors.txt @@ -1,5 +1,5 @@ tests/cases/compiler/extendedInterfacesWithDuplicateTypeParameters.ts(1,42): error TS2300: Duplicate identifier 'A'. -tests/cases/compiler/extendedInterfacesWithDuplicateTypeParameters.ts(9,11): error TS2428: All declarations of an interface must have identical type parameters. +tests/cases/compiler/extendedInterfacesWithDuplicateTypeParameters.ts(9,11): error TS2428: All declarations of 'InterfaceWithSomeTypars' must have identical type parameters. tests/cases/compiler/extendedInterfacesWithDuplicateTypeParameters.ts(9,38): error TS2300: Duplicate identifier 'C'. @@ -16,7 +16,7 @@ tests/cases/compiler/extendedInterfacesWithDuplicateTypeParameters.ts(9,38): err interface InterfaceWithSomeTypars { // should error ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2428: All declarations of an interface must have identical type parameters. +!!! error TS2428: All declarations of 'InterfaceWithSomeTypars' must have identical type parameters. ~ !!! error TS2300: Duplicate identifier 'C'. bar2(): void; diff --git a/tests/baselines/reference/genericAndNonGenericInterfaceWithTheSameName.errors.txt b/tests/baselines/reference/genericAndNonGenericInterfaceWithTheSameName.errors.txt index 4c3245b11f7..8d9ebb8d276 100644 --- a/tests/baselines/reference/genericAndNonGenericInterfaceWithTheSameName.errors.txt +++ b/tests/baselines/reference/genericAndNonGenericInterfaceWithTheSameName.errors.txt @@ -1,6 +1,6 @@ -tests/cases/conformance/interfaces/declarationMerging/genericAndNonGenericInterfaceWithTheSameName.ts(7,11): error TS2428: All declarations of an interface must have identical type parameters. -tests/cases/conformance/interfaces/declarationMerging/genericAndNonGenericInterfaceWithTheSameName.ts(16,15): error TS2428: All declarations of an interface must have identical type parameters. -tests/cases/conformance/interfaces/declarationMerging/genericAndNonGenericInterfaceWithTheSameName.ts(40,22): error TS2428: All declarations of an interface must have identical type parameters. +tests/cases/conformance/interfaces/declarationMerging/genericAndNonGenericInterfaceWithTheSameName.ts(7,11): error TS2428: All declarations of 'A' must have identical type parameters. +tests/cases/conformance/interfaces/declarationMerging/genericAndNonGenericInterfaceWithTheSameName.ts(16,15): error TS2428: All declarations of 'A' must have identical type parameters. +tests/cases/conformance/interfaces/declarationMerging/genericAndNonGenericInterfaceWithTheSameName.ts(40,22): error TS2428: All declarations of 'A' must have identical type parameters. ==== tests/cases/conformance/interfaces/declarationMerging/genericAndNonGenericInterfaceWithTheSameName.ts (3 errors) ==== @@ -12,7 +12,7 @@ tests/cases/conformance/interfaces/declarationMerging/genericAndNonGenericInterf interface A { // error ~ -!!! error TS2428: All declarations of an interface must have identical type parameters. +!!! error TS2428: All declarations of 'A' must have identical type parameters. bar: T; } @@ -23,7 +23,7 @@ tests/cases/conformance/interfaces/declarationMerging/genericAndNonGenericInterf interface A { // error ~ -!!! error TS2428: All declarations of an interface must have identical type parameters. +!!! error TS2428: All declarations of 'A' must have identical type parameters. foo: string; } } @@ -49,7 +49,7 @@ tests/cases/conformance/interfaces/declarationMerging/genericAndNonGenericInterf module M3 { export interface A { // error ~ -!!! error TS2428: All declarations of an interface must have identical type parameters. +!!! error TS2428: All declarations of 'A' must have identical type parameters. bar: T; } } \ No newline at end of file diff --git a/tests/baselines/reference/interfaceWithMultipleDeclarations.errors.txt b/tests/baselines/reference/interfaceWithMultipleDeclarations.errors.txt index e4b37db8a7a..79d8b4a509a 100644 --- a/tests/baselines/reference/interfaceWithMultipleDeclarations.errors.txt +++ b/tests/baselines/reference/interfaceWithMultipleDeclarations.errors.txt @@ -1,14 +1,14 @@ -tests/cases/compiler/interfaceWithMultipleDeclarations.ts(3,11): error TS2428: All declarations of an interface must have identical type parameters. -tests/cases/compiler/interfaceWithMultipleDeclarations.ts(5,11): error TS2428: All declarations of an interface must have identical type parameters. -tests/cases/compiler/interfaceWithMultipleDeclarations.ts(7,11): error TS2428: All declarations of an interface must have identical type parameters. -tests/cases/compiler/interfaceWithMultipleDeclarations.ts(9,11): error TS2428: All declarations of an interface must have identical type parameters. -tests/cases/compiler/interfaceWithMultipleDeclarations.ts(11,11): error TS2428: All declarations of an interface must have identical type parameters. -tests/cases/compiler/interfaceWithMultipleDeclarations.ts(16,11): error TS2428: All declarations of an interface must have identical type parameters. -tests/cases/compiler/interfaceWithMultipleDeclarations.ts(18,11): error TS2428: All declarations of an interface must have identical type parameters. -tests/cases/compiler/interfaceWithMultipleDeclarations.ts(20,11): error TS2428: All declarations of an interface must have identical type parameters. -tests/cases/compiler/interfaceWithMultipleDeclarations.ts(22,11): error TS2428: All declarations of an interface must have identical type parameters. -tests/cases/compiler/interfaceWithMultipleDeclarations.ts(24,11): error TS2428: All declarations of an interface must have identical type parameters. -tests/cases/compiler/interfaceWithMultipleDeclarations.ts(29,11): error TS2428: All declarations of an interface must have identical type parameters. +tests/cases/compiler/interfaceWithMultipleDeclarations.ts(3,11): error TS2428: All declarations of 'I1' must have identical type parameters. +tests/cases/compiler/interfaceWithMultipleDeclarations.ts(5,11): error TS2428: All declarations of 'I1' must have identical type parameters. +tests/cases/compiler/interfaceWithMultipleDeclarations.ts(7,11): error TS2428: All declarations of 'I1' must have identical type parameters. +tests/cases/compiler/interfaceWithMultipleDeclarations.ts(9,11): error TS2428: All declarations of 'I1' must have identical type parameters. +tests/cases/compiler/interfaceWithMultipleDeclarations.ts(11,11): error TS2428: All declarations of 'I1' must have identical type parameters. +tests/cases/compiler/interfaceWithMultipleDeclarations.ts(16,11): error TS2428: All declarations of 'I2' must have identical type parameters. +tests/cases/compiler/interfaceWithMultipleDeclarations.ts(18,11): error TS2428: All declarations of 'I2' must have identical type parameters. +tests/cases/compiler/interfaceWithMultipleDeclarations.ts(20,11): error TS2428: All declarations of 'I2' must have identical type parameters. +tests/cases/compiler/interfaceWithMultipleDeclarations.ts(22,11): error TS2428: All declarations of 'I2' must have identical type parameters. +tests/cases/compiler/interfaceWithMultipleDeclarations.ts(24,11): error TS2428: All declarations of 'I2' must have identical type parameters. +tests/cases/compiler/interfaceWithMultipleDeclarations.ts(29,11): error TS2428: All declarations of 'I3' must have identical type parameters. ==== tests/cases/compiler/interfaceWithMultipleDeclarations.ts (11 errors) ==== @@ -16,53 +16,53 @@ tests/cases/compiler/interfaceWithMultipleDeclarations.ts(29,11): error TS2428: } interface I1 { // Name mismatch ~~ -!!! error TS2428: All declarations of an interface must have identical type parameters. +!!! error TS2428: All declarations of 'I1' must have identical type parameters. } interface I1 { // Length mismatch ~~ -!!! error TS2428: All declarations of an interface must have identical type parameters. +!!! error TS2428: All declarations of 'I1' must have identical type parameters. } interface I1 { // constraint present ~~ -!!! error TS2428: All declarations of an interface must have identical type parameters. +!!! error TS2428: All declarations of 'I1' must have identical type parameters. } interface I1 { // Length mismatch ~~ -!!! error TS2428: All declarations of an interface must have identical type parameters. +!!! error TS2428: All declarations of 'I1' must have identical type parameters. } interface I1 { // Length mismatch ~~ -!!! error TS2428: All declarations of an interface must have identical type parameters. +!!! error TS2428: All declarations of 'I1' must have identical type parameters. } interface I2 { } interface I2 string> { // constraint mismatch ~~ -!!! error TS2428: All declarations of an interface must have identical type parameters. +!!! error TS2428: All declarations of 'I2' must have identical type parameters. } interface I2 { // constraint absent ~~ -!!! error TS2428: All declarations of an interface must have identical type parameters. +!!! error TS2428: All declarations of 'I2' must have identical type parameters. } interface I2 { // name mismatch ~~ -!!! error TS2428: All declarations of an interface must have identical type parameters. +!!! error TS2428: All declarations of 'I2' must have identical type parameters. } interface I2 { // length mismatch ~~ -!!! error TS2428: All declarations of an interface must have identical type parameters. +!!! error TS2428: All declarations of 'I2' must have identical type parameters. } interface I2 { // length mismatch ~~ -!!! error TS2428: All declarations of an interface must have identical type parameters. +!!! error TS2428: All declarations of 'I2' must have identical type parameters. } interface I3 { } interface I3 { // length mismatch ~~ -!!! error TS2428: All declarations of an interface must have identical type parameters. +!!! error TS2428: All declarations of 'I3' must have identical type parameters. } class Foo { diff --git a/tests/baselines/reference/multipleNumericIndexers.errors.txt b/tests/baselines/reference/multipleNumericIndexers.errors.txt index 856fdbe47ff..82fc444ac65 100644 --- a/tests/baselines/reference/multipleNumericIndexers.errors.txt +++ b/tests/baselines/reference/multipleNumericIndexers.errors.txt @@ -3,7 +3,7 @@ tests/cases/conformance/types/objectTypeLiteral/indexSignatures/multipleNumericI tests/cases/conformance/types/objectTypeLiteral/indexSignatures/multipleNumericIndexers.ts(15,5): error TS2375: Duplicate number index signature. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/multipleNumericIndexers.ts(20,5): error TS2375: Duplicate number index signature. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/multipleNumericIndexers.ts(25,5): error TS2375: Duplicate number index signature. -tests/cases/conformance/types/objectTypeLiteral/indexSignatures/multipleNumericIndexers.ts(28,11): error TS2428: All declarations of an interface must have identical type parameters. +tests/cases/conformance/types/objectTypeLiteral/indexSignatures/multipleNumericIndexers.ts(28,11): error TS2428: All declarations of 'I' must have identical type parameters. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/multipleNumericIndexers.ts(29,5): error TS2375: Duplicate number index signature. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/multipleNumericIndexers.ts(30,5): error TS2375: Duplicate number index signature. @@ -48,7 +48,7 @@ tests/cases/conformance/types/objectTypeLiteral/indexSignatures/multipleNumericI interface I { ~ -!!! error TS2428: All declarations of an interface must have identical type parameters. +!!! error TS2428: All declarations of 'I' must have identical type parameters. [x: number]: string; ~~~~~~~~~~~~~~~~~~~~ !!! error TS2375: Duplicate number index signature. diff --git a/tests/baselines/reference/nonIdenticalTypeConstraints.errors.txt b/tests/baselines/reference/nonIdenticalTypeConstraints.errors.txt new file mode 100644 index 00000000000..627b38579a2 --- /dev/null +++ b/tests/baselines/reference/nonIdenticalTypeConstraints.errors.txt @@ -0,0 +1,50 @@ +tests/cases/compiler/nonIdenticalTypeConstraints.ts(10,11): error TS2428: All declarations of 'Foo' must have identical type parameters. +tests/cases/compiler/nonIdenticalTypeConstraints.ts(16,7): error TS2428: All declarations of 'Qux' must have identical type parameters. +tests/cases/compiler/nonIdenticalTypeConstraints.ts(36,11): error TS2428: All declarations of 'Quux' must have identical type parameters. + + +==== tests/cases/compiler/nonIdenticalTypeConstraints.ts (3 errors) ==== + class Different { + a: number; + b: string; + c: boolean; + } + + class Foo { + n: T; + } + interface Foo { + ~~~ +!!! error TS2428: All declarations of 'Foo' must have identical type parameters. + y: T; + } + interface Qux { + y: T; + } + class Qux { + ~~~ +!!! error TS2428: All declarations of 'Qux' must have identical type parameters. + n: T; + } + + class Bar { + n: T; + } + interface Bar { + y: T; + } + interface Baz { + y: T; + } + class Baz { + n: T; + } + + class Quux { + n: T; + } + interface Quux { + ~~~~ +!!! error TS2428: All declarations of 'Quux' must have identical type parameters. + m: U; + } \ No newline at end of file diff --git a/tests/baselines/reference/nonIdenticalTypeConstraints.js b/tests/baselines/reference/nonIdenticalTypeConstraints.js new file mode 100644 index 00000000000..73748f63885 --- /dev/null +++ b/tests/baselines/reference/nonIdenticalTypeConstraints.js @@ -0,0 +1,71 @@ +//// [nonIdenticalTypeConstraints.ts] +class Different { + a: number; + b: string; + c: boolean; +} + +class Foo { + n: T; +} +interface Foo { + y: T; +} +interface Qux { + y: T; +} +class Qux { + n: T; +} + +class Bar { + n: T; +} +interface Bar { + y: T; +} +interface Baz { + y: T; +} +class Baz { + n: T; +} + +class Quux { + n: T; +} +interface Quux { + m: U; +} + +//// [nonIdenticalTypeConstraints.js] +var Different = (function () { + function Different() { + } + return Different; +}()); +var Foo = (function () { + function Foo() { + } + return Foo; +}()); +var Qux = (function () { + function Qux() { + } + return Qux; +}()); +var Bar = (function () { + function Bar() { + } + return Bar; +}()); +var Baz = (function () { + function Baz() { + } + return Baz; +}()); +var Quux = (function () { + function Quux() { + } + return Quux; +}()); diff --git a/tests/baselines/reference/twoGenericInterfacesDifferingByTypeParameterName.errors.txt b/tests/baselines/reference/twoGenericInterfacesDifferingByTypeParameterName.errors.txt index adf9583095d..6c0f562ac64 100644 --- a/tests/baselines/reference/twoGenericInterfacesDifferingByTypeParameterName.errors.txt +++ b/tests/baselines/reference/twoGenericInterfacesDifferingByTypeParameterName.errors.txt @@ -1,8 +1,8 @@ -tests/cases/conformance/interfaces/declarationMerging/twoGenericInterfacesDifferingByTypeParameterName.ts(7,11): error TS2428: All declarations of an interface must have identical type parameters. -tests/cases/conformance/interfaces/declarationMerging/twoGenericInterfacesDifferingByTypeParameterName.ts(15,11): error TS2428: All declarations of an interface must have identical type parameters. -tests/cases/conformance/interfaces/declarationMerging/twoGenericInterfacesDifferingByTypeParameterName.ts(24,15): error TS2428: All declarations of an interface must have identical type parameters. -tests/cases/conformance/interfaces/declarationMerging/twoGenericInterfacesDifferingByTypeParameterName.ts(32,15): error TS2428: All declarations of an interface must have identical type parameters. -tests/cases/conformance/interfaces/declarationMerging/twoGenericInterfacesDifferingByTypeParameterName.ts(56,22): error TS2428: All declarations of an interface must have identical type parameters. +tests/cases/conformance/interfaces/declarationMerging/twoGenericInterfacesDifferingByTypeParameterName.ts(7,11): error TS2428: All declarations of 'A' must have identical type parameters. +tests/cases/conformance/interfaces/declarationMerging/twoGenericInterfacesDifferingByTypeParameterName.ts(15,11): error TS2428: All declarations of 'B' must have identical type parameters. +tests/cases/conformance/interfaces/declarationMerging/twoGenericInterfacesDifferingByTypeParameterName.ts(24,15): error TS2428: All declarations of 'A' must have identical type parameters. +tests/cases/conformance/interfaces/declarationMerging/twoGenericInterfacesDifferingByTypeParameterName.ts(32,15): error TS2428: All declarations of 'B' must have identical type parameters. +tests/cases/conformance/interfaces/declarationMerging/twoGenericInterfacesDifferingByTypeParameterName.ts(56,22): error TS2428: All declarations of 'B' must have identical type parameters. ==== tests/cases/conformance/interfaces/declarationMerging/twoGenericInterfacesDifferingByTypeParameterName.ts (5 errors) ==== @@ -14,7 +14,7 @@ tests/cases/conformance/interfaces/declarationMerging/twoGenericInterfacesDiffer interface A { // error ~ -!!! error TS2428: All declarations of an interface must have identical type parameters. +!!! error TS2428: All declarations of 'A' must have identical type parameters. y: U; } @@ -24,7 +24,7 @@ tests/cases/conformance/interfaces/declarationMerging/twoGenericInterfacesDiffer interface B { // error ~ -!!! error TS2428: All declarations of an interface must have identical type parameters. +!!! error TS2428: All declarations of 'B' must have identical type parameters. y: V; } @@ -35,7 +35,7 @@ tests/cases/conformance/interfaces/declarationMerging/twoGenericInterfacesDiffer interface A { // error ~ -!!! error TS2428: All declarations of an interface must have identical type parameters. +!!! error TS2428: All declarations of 'A' must have identical type parameters. y: U; } @@ -45,7 +45,7 @@ tests/cases/conformance/interfaces/declarationMerging/twoGenericInterfacesDiffer interface B { // error ~ -!!! error TS2428: All declarations of an interface must have identical type parameters. +!!! error TS2428: All declarations of 'B' must have identical type parameters. y: V; } } @@ -71,7 +71,7 @@ tests/cases/conformance/interfaces/declarationMerging/twoGenericInterfacesDiffer module M3 { export interface B { // error ~ -!!! error TS2428: All declarations of an interface must have identical type parameters. +!!! error TS2428: All declarations of 'B' must have identical type parameters. y: V; } } diff --git a/tests/baselines/reference/twoGenericInterfacesDifferingByTypeParameterName2.errors.txt b/tests/baselines/reference/twoGenericInterfacesDifferingByTypeParameterName2.errors.txt index dd1483b9e1d..f2a0063c230 100644 --- a/tests/baselines/reference/twoGenericInterfacesDifferingByTypeParameterName2.errors.txt +++ b/tests/baselines/reference/twoGenericInterfacesDifferingByTypeParameterName2.errors.txt @@ -1,7 +1,7 @@ -tests/cases/conformance/interfaces/declarationMerging/twoGenericInterfacesDifferingByTypeParameterName2.ts(7,11): error TS2428: All declarations of an interface must have identical type parameters. +tests/cases/conformance/interfaces/declarationMerging/twoGenericInterfacesDifferingByTypeParameterName2.ts(7,11): error TS2428: All declarations of 'B' must have identical type parameters. tests/cases/conformance/interfaces/declarationMerging/twoGenericInterfacesDifferingByTypeParameterName2.ts(8,8): error TS2304: Cannot find name 'V'. -tests/cases/conformance/interfaces/declarationMerging/twoGenericInterfacesDifferingByTypeParameterName2.ts(16,15): error TS2428: All declarations of an interface must have identical type parameters. -tests/cases/conformance/interfaces/declarationMerging/twoGenericInterfacesDifferingByTypeParameterName2.ts(40,22): error TS2428: All declarations of an interface must have identical type parameters. +tests/cases/conformance/interfaces/declarationMerging/twoGenericInterfacesDifferingByTypeParameterName2.ts(16,15): error TS2428: All declarations of 'B' must have identical type parameters. +tests/cases/conformance/interfaces/declarationMerging/twoGenericInterfacesDifferingByTypeParameterName2.ts(40,22): error TS2428: All declarations of 'B' must have identical type parameters. ==== tests/cases/conformance/interfaces/declarationMerging/twoGenericInterfacesDifferingByTypeParameterName2.ts (4 errors) ==== @@ -13,7 +13,7 @@ tests/cases/conformance/interfaces/declarationMerging/twoGenericInterfacesDiffer interface B { // error ~ -!!! error TS2428: All declarations of an interface must have identical type parameters. +!!! error TS2428: All declarations of 'B' must have identical type parameters. y: V; ~ !!! error TS2304: Cannot find name 'V'. @@ -26,7 +26,7 @@ tests/cases/conformance/interfaces/declarationMerging/twoGenericInterfacesDiffer interface B { // error ~ -!!! error TS2428: All declarations of an interface must have identical type parameters. +!!! error TS2428: All declarations of 'B' must have identical type parameters. y: T; } } @@ -52,7 +52,7 @@ tests/cases/conformance/interfaces/declarationMerging/twoGenericInterfacesDiffer module M3 { export interface B { // error ~ -!!! error TS2428: All declarations of an interface must have identical type parameters. +!!! error TS2428: All declarations of 'B' must have identical type parameters. y: T; } } diff --git a/tests/baselines/reference/twoGenericInterfacesWithDifferentConstraints.errors.txt b/tests/baselines/reference/twoGenericInterfacesWithDifferentConstraints.errors.txt index 665a26f47f4..4b2455773f5 100644 --- a/tests/baselines/reference/twoGenericInterfacesWithDifferentConstraints.errors.txt +++ b/tests/baselines/reference/twoGenericInterfacesWithDifferentConstraints.errors.txt @@ -1,6 +1,6 @@ -tests/cases/conformance/interfaces/declarationMerging/twoGenericInterfacesWithDifferentConstraints.ts(5,11): error TS2428: All declarations of an interface must have identical type parameters. -tests/cases/conformance/interfaces/declarationMerging/twoGenericInterfacesWithDifferentConstraints.ts(14,15): error TS2428: All declarations of an interface must have identical type parameters. -tests/cases/conformance/interfaces/declarationMerging/twoGenericInterfacesWithDifferentConstraints.ts(38,22): error TS2428: All declarations of an interface must have identical type parameters. +tests/cases/conformance/interfaces/declarationMerging/twoGenericInterfacesWithDifferentConstraints.ts(5,11): error TS2428: All declarations of 'A' must have identical type parameters. +tests/cases/conformance/interfaces/declarationMerging/twoGenericInterfacesWithDifferentConstraints.ts(14,15): error TS2428: All declarations of 'B' must have identical type parameters. +tests/cases/conformance/interfaces/declarationMerging/twoGenericInterfacesWithDifferentConstraints.ts(38,22): error TS2428: All declarations of 'A' must have identical type parameters. ==== tests/cases/conformance/interfaces/declarationMerging/twoGenericInterfacesWithDifferentConstraints.ts (3 errors) ==== @@ -10,7 +10,7 @@ tests/cases/conformance/interfaces/declarationMerging/twoGenericInterfacesWithDi interface A { // error ~ -!!! error TS2428: All declarations of an interface must have identical type parameters. +!!! error TS2428: All declarations of 'A' must have identical type parameters. y: T; } @@ -21,7 +21,7 @@ tests/cases/conformance/interfaces/declarationMerging/twoGenericInterfacesWithDi interface B> { // error ~ -!!! error TS2428: All declarations of an interface must have identical type parameters. +!!! error TS2428: All declarations of 'B' must have identical type parameters. y: T; } } @@ -47,7 +47,7 @@ tests/cases/conformance/interfaces/declarationMerging/twoGenericInterfacesWithDi module M3 { export interface A { // error ~ -!!! error TS2428: All declarations of an interface must have identical type parameters. +!!! error TS2428: All declarations of 'A' must have identical type parameters. y: T; } } \ No newline at end of file diff --git a/tests/baselines/reference/twoGenericInterfacesWithTheSameNameButDifferentArity.errors.txt b/tests/baselines/reference/twoGenericInterfacesWithTheSameNameButDifferentArity.errors.txt index be0608c0cd6..de4c4d8e1c3 100644 --- a/tests/baselines/reference/twoGenericInterfacesWithTheSameNameButDifferentArity.errors.txt +++ b/tests/baselines/reference/twoGenericInterfacesWithTheSameNameButDifferentArity.errors.txt @@ -1,6 +1,6 @@ -tests/cases/conformance/interfaces/declarationMerging/twoGenericInterfacesWithTheSameNameButDifferentArity.ts(5,11): error TS2428: All declarations of an interface must have identical type parameters. -tests/cases/conformance/interfaces/declarationMerging/twoGenericInterfacesWithTheSameNameButDifferentArity.ts(14,15): error TS2428: All declarations of an interface must have identical type parameters. -tests/cases/conformance/interfaces/declarationMerging/twoGenericInterfacesWithTheSameNameButDifferentArity.ts(38,22): error TS2428: All declarations of an interface must have identical type parameters. +tests/cases/conformance/interfaces/declarationMerging/twoGenericInterfacesWithTheSameNameButDifferentArity.ts(5,11): error TS2428: All declarations of 'A' must have identical type parameters. +tests/cases/conformance/interfaces/declarationMerging/twoGenericInterfacesWithTheSameNameButDifferentArity.ts(14,15): error TS2428: All declarations of 'A' must have identical type parameters. +tests/cases/conformance/interfaces/declarationMerging/twoGenericInterfacesWithTheSameNameButDifferentArity.ts(38,22): error TS2428: All declarations of 'A' must have identical type parameters. ==== tests/cases/conformance/interfaces/declarationMerging/twoGenericInterfacesWithTheSameNameButDifferentArity.ts (3 errors) ==== @@ -10,7 +10,7 @@ tests/cases/conformance/interfaces/declarationMerging/twoGenericInterfacesWithTh interface A { // error ~ -!!! error TS2428: All declarations of an interface must have identical type parameters. +!!! error TS2428: All declarations of 'A' must have identical type parameters. y: T; } @@ -21,7 +21,7 @@ tests/cases/conformance/interfaces/declarationMerging/twoGenericInterfacesWithTh interface A { // error ~ -!!! error TS2428: All declarations of an interface must have identical type parameters. +!!! error TS2428: All declarations of 'A' must have identical type parameters. y: T; } } @@ -47,7 +47,7 @@ tests/cases/conformance/interfaces/declarationMerging/twoGenericInterfacesWithTh module M3 { export interface A { // error ~ -!!! error TS2428: All declarations of an interface must have identical type parameters. +!!! error TS2428: All declarations of 'A' must have identical type parameters. y: T; } } \ No newline at end of file diff --git a/tests/cases/compiler/nonIdenticalTypeConstraints.ts b/tests/cases/compiler/nonIdenticalTypeConstraints.ts new file mode 100644 index 00000000000..c0271edc91a --- /dev/null +++ b/tests/cases/compiler/nonIdenticalTypeConstraints.ts @@ -0,0 +1,38 @@ +class Different { + a: number; + b: string; + c: boolean; +} + +class Foo { + n: T; +} +interface Foo { + y: T; +} +interface Qux { + y: T; +} +class Qux { + n: T; +} + +class Bar { + n: T; +} +interface Bar { + y: T; +} +interface Baz { + y: T; +} +class Baz { + n: T; +} + +class Quux { + n: T; +} +interface Quux { + m: U; +} \ No newline at end of file