@@ -2303,7 +2303,7 @@ namespace ts {
23032303                else {
23042304                    Debug.assert(!!(result.flags & SymbolFlags.ConstEnum));
23052305                    if (compilerOptions.preserveConstEnums) {
2306-                         diagnosticMessage = error(errorLocation, Diagnostics.Class_0_used_before_its_declaration , declarationName);
2306+                         diagnosticMessage = error(errorLocation, Diagnostics.Enum_0_used_before_its_declaration , declarationName);
23072307                    }
23082308                }
23092309
@@ -4155,12 +4155,16 @@ namespace ts {
41554155            let leftStr = symbolValueDeclarationIsContextSensitive(left.symbol) ? typeToString(left, left.symbol.valueDeclaration) : typeToString(left);
41564156            let rightStr = symbolValueDeclarationIsContextSensitive(right.symbol) ? typeToString(right, right.symbol.valueDeclaration) : typeToString(right);
41574157            if (leftStr === rightStr) {
4158-                 leftStr = typeToString (left, /*enclosingDeclaration*/ undefined, TypeFormatFlags.UseFullyQualifiedType );
4159-                 rightStr = typeToString (right, /*enclosingDeclaration*/ undefined, TypeFormatFlags.UseFullyQualifiedType );
4158+                 leftStr = getTypeNameForErrorDisplay (left);
4159+                 rightStr = getTypeNameForErrorDisplay (right);
41604160            }
41614161            return [leftStr, rightStr];
41624162        }
41634163
4164+         function getTypeNameForErrorDisplay(type: Type) {
4165+             return typeToString(type, /*enclosingDeclaration*/ undefined, TypeFormatFlags.UseFullyQualifiedType);
4166+         }
4167+ 
41644168        function symbolValueDeclarationIsContextSensitive(symbol: Symbol): boolean {
41654169            return symbol && symbol.valueDeclaration && isExpression(symbol.valueDeclaration) && !isContextSensitive(symbol.valueDeclaration);
41664170        }
@@ -15742,23 +15746,30 @@ namespace ts {
1574215746            function reportRelationError(message: DiagnosticMessage | undefined, source: Type, target: Type) {
1574315747                if (incompatibleStack.length) reportIncompatibleStack();
1574415748                const [sourceType, targetType] = getTypeNamesForErrorDisplay(source, target);
15749+                 let generalizedSource = source;
15750+                 let generalizedSourceType = sourceType;
15751+ 
15752+                 if (isLiteralType(source) && !typeCouldHaveTopLevelSingletonTypes(target)) {
15753+                     generalizedSource = getBaseTypeOfLiteralType(source);
15754+                     generalizedSourceType = getTypeNameForErrorDisplay(generalizedSource);
15755+                 }
1574515756
1574615757                if (target.flags & TypeFlags.TypeParameter) {
1574715758                    const constraint = getBaseConstraintOfType(target);
15748-                     const constraintElab = constraint && isTypeAssignableTo(source, constraint) ;
15749-                     if (constraintElab ) {
15759+                     let needsOriginalSource ;
15760+                     if (constraint && (isTypeAssignableTo(generalizedSource, constraint) || (needsOriginalSource = isTypeAssignableTo(source, constraint))) ) {
1575015761                        reportError(
1575115762                            Diagnostics._0_is_assignable_to_the_constraint_of_type_1_but_1_could_be_instantiated_with_a_different_subtype_of_constraint_2,
15752-                             sourceType,
15763+                             needsOriginalSource ?  sourceType : generalizedSourceType ,
1575315764                            targetType,
15754-                             typeToString(constraint! ),
15765+                             typeToString(constraint),
1575515766                        );
1575615767                    }
1575715768                    else {
1575815769                        reportError(
1575915770                            Diagnostics._0_could_be_instantiated_with_an_arbitrary_type_which_could_be_unrelated_to_1,
1576015771                            targetType,
15761-                             sourceType 
15772+                             generalizedSourceType 
1576215773                        );
1576315774                    }
1576415775                }
@@ -15775,7 +15786,7 @@ namespace ts {
1577515786                    }
1577615787                }
1577715788
15778-                 reportError(message, sourceType , targetType);
15789+                 reportError(message, generalizedSourceType , targetType);
1577915790            }
1578015791
1578115792            function tryElaborateErrorsForPrimitivesAndObjects(source: Type, target: Type) {
@@ -17304,9 +17315,10 @@ namespace ts {
1730417315                    return Ternary.True;
1730517316                }
1730617317                if (isGenericMappedType(source)) {
17307-                     // A generic mapped type { [P in K]: T } is related to an index signature { [x: string]: U }
17308-                     // if T is related to U.
17309-                     return kind === IndexKind.String ? isRelatedTo(getTemplateTypeFromMappedType(source), targetType, reportErrors) : Ternary.False;
17318+                     // A generic mapped type { [P in K]: T } is related to a type with an index signature
17319+                     // { [x: string]: U }, and optionally with an index signature { [x: number]: V },
17320+                     // if T is related to U and V.
17321+                     return getIndexTypeOfType(target, IndexKind.String) ? isRelatedTo(getTemplateTypeFromMappedType(source), targetType, reportErrors) : Ternary.False;
1731017322                }
1731117323                const indexType = getIndexTypeOfType(source, kind) || kind === IndexKind.Number && getIndexTypeOfType(source, IndexKind.String);
1731217324                if (indexType) {
@@ -17372,6 +17384,21 @@ namespace ts {
1737217384            }
1737317385        }
1737417386
17387+         function typeCouldHaveTopLevelSingletonTypes(type: Type): boolean {
17388+             if (type.flags & TypeFlags.UnionOrIntersection) {
17389+                 return !!forEach((type as IntersectionType).types, typeCouldHaveTopLevelSingletonTypes);
17390+             }
17391+ 
17392+             if (type.flags & TypeFlags.Instantiable) {
17393+                 const constraint = getConstraintOfType(type);
17394+                 if (constraint) {
17395+                     return typeCouldHaveTopLevelSingletonTypes(constraint);
17396+                 }
17397+             }
17398+ 
17399+             return isUnitType(type);
17400+         }
17401+ 
1737517402        function getBestMatchingType(source: Type, target: UnionOrIntersectionType, isRelatedTo = compareTypesAssignable) {
1737617403            return findMatchingDiscriminantType(source, target, isRelatedTo, /*skipPartial*/ true) ||
1737717404                findMatchingTypeReferenceOrTypeAliasReference(source, target) ||
@@ -33850,8 +33877,7 @@ namespace ts {
3385033877                    const derivedPropertyFlags = derived.flags & SymbolFlags.PropertyOrAccessor;
3385133878                    if (basePropertyFlags && derivedPropertyFlags) {
3385233879                        // property/accessor is overridden with property/accessor
33853-                         if (!compilerOptions.useDefineForClassFields
33854-                             || baseDeclarationFlags & ModifierFlags.Abstract && !(base.valueDeclaration && isPropertyDeclaration(base.valueDeclaration) && base.valueDeclaration.initializer)
33880+                         if (baseDeclarationFlags & ModifierFlags.Abstract && !(base.valueDeclaration && isPropertyDeclaration(base.valueDeclaration) && base.valueDeclaration.initializer)
3385533881                            || base.valueDeclaration && base.valueDeclaration.parent.kind === SyntaxKind.InterfaceDeclaration
3385633882                            || derived.valueDeclaration && isBinaryExpression(derived.valueDeclaration)) {
3385733883                            // when the base property is abstract or from an interface, base/derived flags don't need to match
@@ -33867,7 +33893,7 @@ namespace ts {
3386733893                                Diagnostics._0_is_defined_as_a_property_in_class_1_but_is_overridden_here_in_2_as_an_accessor;
3386833894                            error(getNameOfDeclaration(derived.valueDeclaration) || derived.valueDeclaration, errorMessage, symbolToString(base), typeToString(baseType), typeToString(type));
3386933895                        }
33870-                         else {
33896+                         else if (compilerOptions.useDefineForClassFields)  {
3387133897                            const uninitialized = find(derived.declarations, d => d.kind === SyntaxKind.PropertyDeclaration && !(d as PropertyDeclaration).initializer);
3387233898                            if (uninitialized
3387333899                                && !(derived.flags & SymbolFlags.Transient)
0 commit comments