mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-29 19:42:39 -05:00
Adds error message for incompatible assignment of identically named type
Fixes issue #12050
This commit is contained in:
@@ -6824,9 +6824,15 @@ namespace ts {
|
||||
}
|
||||
|
||||
if (!message) {
|
||||
message = relation === comparableRelation ?
|
||||
Diagnostics.Type_0_is_not_comparable_to_type_1 :
|
||||
Diagnostics.Type_0_is_not_assignable_to_type_1;
|
||||
if (relation === comparableRelation) {
|
||||
message = Diagnostics.Type_0_is_not_comparable_to_type_1;
|
||||
}
|
||||
else if (sourceType === targetType) {
|
||||
message = Diagnostics.Type_0_is_not_assignable_to_type_1_Two_different_types_with_this_name_exist_but_they_are_unrelated;
|
||||
}
|
||||
else {
|
||||
message = Diagnostics.Type_0_is_not_assignable_to_type_1;
|
||||
}
|
||||
}
|
||||
|
||||
reportError(message, sourceType, targetType);
|
||||
|
||||
@@ -3170,5 +3170,9 @@
|
||||
"Adding a tsconfig.json file will help organize projects that contain both TypeScript and JavaScript files. Learn more at https://aka.ms/tsconfig": {
|
||||
"category": "Error",
|
||||
"code": 90009
|
||||
},
|
||||
"Type '{0}' is not assignable to type '{1}'. Two different types with this name exist, but they are unrelated.": {
|
||||
"category": "Error",
|
||||
"code": 90010
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
tests/cases/compiler/incompatibleAssignmentOfIdenticallyNamedTypes.ts(6,9): error TS90010: Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated.
|
||||
|
||||
|
||||
==== tests/cases/compiler/incompatibleAssignmentOfIdenticallyNamedTypes.ts (1 errors) ====
|
||||
interface T { }
|
||||
declare const a: T;
|
||||
class Foo<T> {
|
||||
x: T;
|
||||
fn() {
|
||||
this.x = a;
|
||||
~~~~~~
|
||||
!!! error TS90010: Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated.
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
//// [incompatibleAssignmentOfIdenticallyNamedTypes.ts]
|
||||
interface T { }
|
||||
declare const a: T;
|
||||
class Foo<T> {
|
||||
x: T;
|
||||
fn() {
|
||||
this.x = a;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//// [incompatibleAssignmentOfIdenticallyNamedTypes.js]
|
||||
var Foo = (function () {
|
||||
function Foo() {
|
||||
}
|
||||
Foo.prototype.fn = function () {
|
||||
this.x = a;
|
||||
};
|
||||
return Foo;
|
||||
}());
|
||||
@@ -0,0 +1,8 @@
|
||||
interface T { }
|
||||
declare const a: T;
|
||||
class Foo<T> {
|
||||
x: T;
|
||||
fn() {
|
||||
this.x = a;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user