mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-22 12:03:44 -05:00
Feed generalized source type to elaboration.
This commit is contained in:
@@ -15730,24 +15730,34 @@ namespace ts {
|
||||
function reportRelationError(message: DiagnosticMessage | undefined, source: Type, target: Type) {
|
||||
if (incompatibleStack.length) reportIncompatibleStack();
|
||||
const [sourceType, targetType] = getTypeNamesForErrorDisplay(source, target);
|
||||
let generalizedSourceType = sourceType;
|
||||
let generalizedSource: Type;
|
||||
let generalizedSourceType: string;
|
||||
|
||||
if (isLiteralType(source) && !typeCouldHaveTopLevelSingletonTypes(target)) {
|
||||
generalizedSource = getBaseTypeOfLiteralType(source);
|
||||
generalizedSourceType = getTypeNameForErrorDisplay(generalizedSource);
|
||||
}
|
||||
else {
|
||||
generalizedSource = source;
|
||||
generalizedSourceType = sourceType;
|
||||
}
|
||||
|
||||
if (target.flags & TypeFlags.TypeParameter) {
|
||||
const constraint = getBaseConstraintOfType(target);
|
||||
const constraintElab = constraint && isTypeAssignableTo(source, constraint);
|
||||
if (constraintElab) {
|
||||
let needsOriginalSource;
|
||||
if (constraint && (isTypeAssignableTo(generalizedSource, constraint) || (needsOriginalSource = isTypeAssignableTo(source, constraint)))) {
|
||||
reportError(
|
||||
Diagnostics._0_is_assignable_to_the_constraint_of_type_1_but_1_could_be_instantiated_with_a_different_subtype_of_constraint_2,
|
||||
sourceType,
|
||||
needsOriginalSource ? sourceType : generalizedSourceType,
|
||||
targetType,
|
||||
typeToString(constraint!),
|
||||
typeToString(constraint),
|
||||
);
|
||||
}
|
||||
else {
|
||||
reportError(
|
||||
Diagnostics._0_could_be_instantiated_with_an_arbitrary_type_which_could_be_unrelated_to_1,
|
||||
targetType,
|
||||
sourceType
|
||||
generalizedSourceType
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -15764,10 +15774,6 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
if (isLiteralType(source) && !typeCouldHaveTopLevelSingletonTypes(target)) {
|
||||
generalizedSourceType = getTypeNameForErrorDisplay(getBaseTypeOfLiteralType(source));
|
||||
}
|
||||
|
||||
reportError(message, generalizedSourceType, targetType);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user