mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-25 16:07:52 -05:00
Skip IntrinsicAttributes elaboration in JSX errors (#24461)
* Skip IntrinsicAttributes elaboration in JSX errors Do not issue an error message for a source type that comes from JSX attributes and a target type that is an intersection containing IntrinsicAttributes or IntrinsicClassAttributes. This will make error messages simpler and less confusing. Note: 1. There will always be elaboration under the skipped message, so this won't elide errors completely. 2. Rarely (once in the tests) the intersection type will have more that one non-Intrinsic* member. However, these additional members don't provide useful information either, so it's fine to skip them. * Add test of IntrinsicAttributes error * Fix indentation in test
This commit is contained in:
committed by
GitHub
parent
c1a5d9bb06
commit
15bfaf1cf6
@@ -10592,6 +10592,16 @@ namespace ts {
|
||||
else if (source.symbol && source.flags & TypeFlags.Object && globalObjectType === source) {
|
||||
reportError(Diagnostics.The_Object_type_is_assignable_to_very_few_other_types_Did_you_mean_to_use_the_any_type_instead);
|
||||
}
|
||||
else if (getObjectFlags(source) & ObjectFlags.JsxAttributes && target.flags & TypeFlags.Intersection) {
|
||||
const targetTypes = (target as IntersectionType).types;
|
||||
const intrinsicAttributes = getJsxType(JsxNames.IntrinsicAttributes, errorNode);
|
||||
const intrinsicClassAttributes = getJsxType(JsxNames.IntrinsicClassAttributes, errorNode);
|
||||
if (intrinsicAttributes !== unknownType && intrinsicClassAttributes !== unknownType &&
|
||||
(contains(targetTypes, intrinsicAttributes) || contains(targetTypes, intrinsicClassAttributes))) {
|
||||
// do not report top error
|
||||
return result;
|
||||
}
|
||||
}
|
||||
reportRelationError(headMessage, source, target);
|
||||
}
|
||||
return result;
|
||||
@@ -16274,7 +16284,7 @@ namespace ts {
|
||||
return createJsxAttributesTypeFromAttributesProperty(node.parent, checkMode);
|
||||
}
|
||||
|
||||
function getJsxType(name: __String, location: Node) {
|
||||
function getJsxType(name: __String, location: Node | undefined) {
|
||||
const namespace = getJsxNamespaceAt(location);
|
||||
const exports = namespace && getExportsOfSymbol(namespace);
|
||||
const typeSymbol = exports && getSymbol(exports, name, SymbolFlags.Type);
|
||||
@@ -16372,7 +16382,7 @@ namespace ts {
|
||||
return getSignatureInstantiation(signature, args, isJavascript);
|
||||
}
|
||||
|
||||
function getJsxNamespaceAt(location: Node): Symbol {
|
||||
function getJsxNamespaceAt(location: Node | undefined): Symbol {
|
||||
const namespaceName = getJsxNamespace(location);
|
||||
const resolvedNamespace = resolveName(location, namespaceName, SymbolFlags.Namespace, /*diagnosticMessage*/ undefined, namespaceName, /*isUse*/ false);
|
||||
if (resolvedNamespace) {
|
||||
|
||||
Reference in New Issue
Block a user