mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-23 17:30:04 -05:00
Added custom error message when trying to assign constraint type to generic type parameter (#30394)
* Added custom error message when trying to assign constraint type to generic type parameter Fixes #29049. This also adds the new message in chained error messages. `typeParameterDiamond4.errors.txt` shows it appearing twice in the "diamond" scenario. I can't tell if this severely increased amount of nested messages is good or bad...? * Updated diagnostic message per suggestion * Align formatting with local custom
This commit is contained in:
committed by
Ryan Cavanaugh
parent
7016d45447
commit
6e736c120e
@@ -12328,6 +12328,15 @@ namespace ts {
|
||||
function reportRelationError(message: DiagnosticMessage | undefined, source: Type, target: Type) {
|
||||
const [sourceType, targetType] = getTypeNamesForErrorDisplay(source, target);
|
||||
|
||||
if (target.flags & TypeFlags.TypeParameter && target.immediateBaseConstraint !== undefined && isTypeAssignableTo(source, target.immediateBaseConstraint)) {
|
||||
reportError(
|
||||
Diagnostics._0_is_assignable_to_the_constraint_of_type_1_but_1_could_be_instantiated_with_a_different_subtype_of_constraint_2,
|
||||
sourceType,
|
||||
targetType,
|
||||
typeToString(target.immediateBaseConstraint),
|
||||
);
|
||||
}
|
||||
|
||||
if (!message) {
|
||||
if (relation === comparableRelation) {
|
||||
message = Diagnostics.Type_0_is_not_comparable_to_type_1;
|
||||
|
||||
@@ -3096,6 +3096,10 @@
|
||||
"category": "Error",
|
||||
"code": 5074
|
||||
},
|
||||
"'{0}' is assignable to the constraint of type '{1}', but '{1}' could be instantiated with a different subtype of constraint '{2}'.": {
|
||||
"category": "Error",
|
||||
"code": 5075
|
||||
},
|
||||
|
||||
"Generates a sourcemap for each corresponding '.d.ts' file.": {
|
||||
"category": "Message",
|
||||
|
||||
Reference in New Issue
Block a user