-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Skip parent error when reporting JSX excess property checks #56989
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Skip parent error when reporting JSX excess property checks #56989
Conversation
This PR doesn't have any linked issues. Please open an issue that references this PR. From there we can discuss and prioritise. |
src/compiler/checker.ts
Outdated
@@ -21711,10 +21711,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { | |||
const suggestionSymbol = getSuggestedSymbolForNonexistentJSXAttribute(propName, errorTarget); | |||
const suggestion = suggestionSymbol ? symbolToString(suggestionSymbol) : undefined; | |||
if (suggestion) { | |||
reportError(Diagnostics.Property_0_does_not_exist_on_type_1_Did_you_mean_2, propName, typeToString(errorTarget), suggestion); | |||
reportParentSkippedError(Diagnostics.Property_0_does_not_exist_on_type_1_Did_you_mean_2, propName, typeToString(errorTarget), suggestion); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One thing that could also be done here is that this could use a more specific message. The one for object literals is better since it mentions object literals. Perhaps this could mention JSX attributes? Or "literal" JSX attributes?
…OnExcessPropertyJsx # Conflicts: # tests/baselines/reference/tscWatch/incremental/jsxImportSource-option-changed-incremental.js # tests/baselines/reference/tscWatch/incremental/jsxImportSource-option-changed-watch.js
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, if you expand out the code right below the diff, it's exactly the same. I think this makes sense.
On second thought, I think there's some value in the extra object being printed because there's nothing about the code in some of these examples where the Maybe this does actually need a better special-case error. |
To understand better what you are saying... you want to special case |
I'm not sure, really; IIRC we have to manufacture a fake |
It's been a while since I was involved in this code (I remember talking to @weswigham about it a while back). If the mismatch is regarding children, it would be helpful to report a more specific error about children. If it's clearly not, we can probably avoid the elaboration. If it's unclear (e.g. the target is a union type and not all of the constituents have But I don't remember where/how we manufacture a property called |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The generating children is done in createJsxAttributesTypeFromAttributesProperty
in checker.ts
https://github.dev/microsoft/TypeScript/blob/2149a0f31a5bf1b1b9e9c2745efeaa74e95170b9/src/compiler/checker.ts#L32951.
Based on the comments there, it also seems reasonable (and in-line with the special case jsx error messages we've added latelyish) to me to special case children
when children isn't defined in props. But I wonder it would get complicated for error messages where children
only shows up in the elaboration
!!! error TS2769: Overload 3 of 3, '(a: { y1: boolean; y2?: number; y3: boolean; }): Element', gave the following error. | ||
!!! error TS2769: Type 'string' is not assignable to type 'boolean'. | ||
!!! related TS6500 file.tsx:30:38: The expected type comes from property 'y1' which is declared here on type 'IntrinsicAttributes & { y1: boolean; y2?: number; y3: boolean; }' | ||
const e3 = <TestingOptional y1="hello" y2={1000} children="hi" /> | ||
~~~~~~~~~~~~~~~ | ||
!!! error TS2769: No overload matches this call. | ||
!!! error TS2769: Overload 1 of 3, '(a: { y1?: string; y2?: number; }): Element', gave the following error. | ||
!!! error TS2769: Type '{ y1: string; y2: number; children: string; }' is not assignable to type 'IntrinsicAttributes & { y1?: string; y2?: number; }'. | ||
!!! error TS2769: Property 'children' does not exist on type 'IntrinsicAttributes & { y1?: string; y2?: number; }'. | ||
!!! error TS2769: Property 'children' does not exist on type 'IntrinsicAttributes & { y1?: string; y2?: number; }'. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also looks like the current error is placed inconsistently. When it's defined in props, there's other places in the baselines where the error is on the props definition of children
, as opposed here, where it shows up under the tag name.
This is just a small extension of #55152 since that PR didn't touch the JSX-related codepath. cc @RyanCavanaugh