From 85155a7239224bf9a874108491a8ee2c0d3c824f Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Thu, 31 May 2018 09:40:45 -0700 Subject: [PATCH 1/3] JSX errors use JSX terminology Well, as well as I understand it. Regardless, the error message no longer mentions a complex synthetic type that *represents* the component. It just mentions the name of the component. --- src/compiler/checker.ts | 14 ++--- src/compiler/diagnosticMessages.json | 4 ++ .../checkJsxChildrenProperty14.errors.txt | 10 ++-- .../checkJsxChildrenProperty2.errors.txt | 54 +++++++++---------- .../checkJsxChildrenProperty4.errors.txt | 10 ++-- .../checkJsxChildrenProperty5.errors.txt | 26 ++++----- .../checkJsxChildrenProperty7.errors.txt | 34 ++++++------ ...StringLiteralsInJsxAttributes02.errors.txt | 12 ++--- ...sxFactoryDeclarationsLocalTypes.errors.txt | 22 ++++---- ...xChildrenGenericContextualTypes.errors.txt | 38 ++++++------- .../reference/tsxAttributeErrors.errors.txt | 8 +-- .../tsxAttributeResolution1.errors.txt | 6 +-- .../tsxAttributeResolution12.errors.txt | 20 +++---- .../tsxAttributeResolution3.errors.txt | 14 ++--- .../tsxAttributeResolution5.errors.txt | 6 +-- .../tsxAttributeResolution6.errors.txt | 6 +-- .../tsxElementResolution3.errors.txt | 6 +-- .../tsxElementResolution4.errors.txt | 6 +-- .../tsxElementResolution9.errors.txt | 18 +++---- .../tsxIntrinsicAttributeErrors.errors.txt | 6 +-- ...ponentWithDefaultTypeParameter3.errors.txt | 6 +-- ...tsxSpreadAttributesResolution12.errors.txt | 8 +-- ...tsxSpreadAttributesResolution16.errors.txt | 6 +-- .../tsxSpreadAttributesResolution2.errors.txt | 28 +++++----- .../tsxSpreadAttributesResolution5.errors.txt | 8 +-- .../tsxSpreadAttributesResolution6.errors.txt | 10 ++-- ...elessFunctionComponentOverload4.errors.txt | 26 ++++----- ...elessFunctionComponentOverload5.errors.txt | 30 +++++------ ...tsxStatelessFunctionComponents1.errors.txt | 12 ++--- ...ionComponentsWithTypeArguments4.errors.txt | 6 +-- .../reference/tsxUnionElementType6.errors.txt | 12 ++--- 31 files changed, 239 insertions(+), 233 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 7dd798a935d78..e0175c59bd8bd 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -10654,15 +10654,17 @@ 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; + else if (getObjectFlags(source) & ObjectFlags.JsxAttributes) { + const targetTypes = target.flags & TypeFlags.Intersection ? (target as IntersectionType).types : emptyArray; const intrinsicAttributes = getJsxType(JsxNames.IntrinsicAttributes, errorNode); const intrinsicClassAttributes = getJsxType(JsxNames.IntrinsicClassAttributes, errorNode); - if (intrinsicAttributes !== errorType && intrinsicClassAttributes !== errorType && - (contains(targetTypes, intrinsicAttributes) || contains(targetTypes, intrinsicClassAttributes))) { - // do not report top error - return result; + if (intrinsicAttributes === errorType || intrinsicClassAttributes === errorType || + (!contains(targetTypes, intrinsicAttributes) && !contains(targetTypes, intrinsicClassAttributes))) { + // only report an error when the target isn't the intersection type with Intrinsic[Class]Attributes + const componentName = errorNode && isIdentifier(errorNode) ? unescapeLeadingUnderscores(errorNode.escapedText) : "the component"; + reportError(Diagnostics.The_attributes_provided_to_0_are_not_assignable_to_type_1, componentName, typeToString(target)); } + return result; } reportRelationError(headMessage, source, target); } diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 259c1ee4ea5f4..fcedd1ea2d211 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -2068,6 +2068,10 @@ "category": "Error", "code": 2609 }, + "The attributes provided to {0} are not assignable to type '{1}'": { + "category": "Error", + "code": 2610 + }, "Cannot augment module '{0}' with value exports because it resolves to a non-module entity.": { "category": "Error", "code": 2649 diff --git a/tests/baselines/reference/checkJsxChildrenProperty14.errors.txt b/tests/baselines/reference/checkJsxChildrenProperty14.errors.txt index cf999188ebc59..c241d6e8ea5ee 100644 --- a/tests/baselines/reference/checkJsxChildrenProperty14.errors.txt +++ b/tests/baselines/reference/checkJsxChildrenProperty14.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/jsx/file.tsx(42,11): error TS2322: Type '{ children: Element[]; a: number; b: string; }' is not assignable to type 'SingleChildProp'. +tests/cases/conformance/jsx/file.tsx(42,11): error TS2610: The attributes provided to SingleChildComp are not assignable to type 'SingleChildProp' Types of property 'children' are incompatible. Type 'Element[]' is not assignable to type 'Element'. Property 'type' is missing in type 'Element[]'. @@ -48,7 +48,7 @@ tests/cases/conformance/jsx/file.tsx(42,11): error TS2322: Type '{ children: Ele // Error let k5 = <>