Skip to content

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Andarist
Copy link
Contributor

@Andarist Andarist commented Jan 9, 2024

This is just a small extension of #55152 since that PR didn't touch the JSX-related codepath. cc @RyanCavanaugh

@typescript-bot typescript-bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Jan 9, 2024
@typescript-bot
Copy link
Collaborator

This PR doesn't have any linked issues. Please open an issue that references this PR. From there we can discuss and prioritise.

@@ -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);
Copy link
Contributor Author

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
jakebailey
jakebailey previously approved these changes Aug 19, 2024
Copy link
Member

@jakebailey jakebailey left a 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.

@jakebailey jakebailey dismissed their stale review August 19, 2024 18:01

On second thought

@jakebailey
Copy link
Member

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 children prop even comes from.

Maybe this does actually need a better special-case error.

@Andarist
Copy link
Contributor Author

To understand better what you are saying... you want to special case children here because it often comes from JSX children and not from an explicit prop named children? And now we don't see the "normalized props" that were passed to JSX

@jakebailey
Copy link
Member

I'm not sure, really; IIRC we have to manufacture a fake children property since that's not explicitly written out (but is just what you stick inside your element body), so I feel like it must make some sense to also be careful about how we report such an error. But, I guess this is why it's assigned to Daniel and Ryan 😄

@DanielRosenwasser
Copy link
Member

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 children or something) maybe we provide the current error.

But I don't remember where/how we manufacture a property called children and how much the special case actually needs to be generalized.

Copy link
Member

@iisaduan iisaduan left a 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; }'.
Copy link
Member

@iisaduan iisaduan Oct 8, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Uncommitted Bug PR for untriaged, rejected, closed or missing bug
Projects
Status: Needs merge
Development

Successfully merging this pull request may close these issues.

5 participants