Skip to content

Conversation

cknitt
Copy link
Member

@cknitt cknitt commented Oct 4, 2025

Fixes #7722

@cknitt cknitt force-pushed the return-jsx-element branch 2 times, most recently from 64dc1a2 to 80b9809 Compare October 4, 2025 08:25
Copy link

pkg-pr-new bot commented Oct 4, 2025

Open in StackBlitz

rescript

npm i https://pkg.pr.new/rescript-lang/rescript@7939

@rescript/darwin-arm64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/darwin-arm64@7939

@rescript/darwin-x64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/darwin-x64@7939

@rescript/linux-arm64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/linux-arm64@7939

@rescript/linux-x64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/linux-x64@7939

@rescript/runtime

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/runtime@7939

@rescript/win32-x64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/win32-x64@7939

commit: 8fd1296

This has type: int
But it's expected to have type: Jsx.element

In JSX, all content must be JSX elements. You can convert int to a JSX element with React.int. No newline at end of file
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error messages could be further improved for this special case.
Leaving that to @zth. 🙂

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we can do this in a follow up.

@cknitt cknitt requested a review from zth October 4, 2025 13:02
Comment on lines 1 to +2
Hover src/Jsx2.resi 1:4
{"contents": {"kind": "markdown", "value": "```rescript\nprops<string>\n```\n\n---\n\n```\n \n```\n```rescript\ntype props<'first> = {first: 'first}\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22Jsx2.resi%22%2C0%2C0%5D)\n"}}
{"contents": {"kind": "markdown", "value": "```rescript\nJsx.element\n```\n\n---\n\n```\n \n```\n```rescript\ntype Jsx.element\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22Jsx.res%22%2C25%2C0%5D)\n"}}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, is this expected? If so, why?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zth I updated this PR, and this change here is now the only remaining open issue.

However, I think it needs to be solved in analysis. As far as I can see, the hover is on make, so the output was already incorrect before (showing the props type instead of the full function type) and is now incorrect in a different way. 🙂

module M4: {
@react.component
let make: (~first: string, ~fun: string=?, ~second: string=?) => React.element
let make: (~first: string, ~fun: string=?, ~second: string=?) => Jsx.element
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting change. I would assume we'd still want it to be React.element?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As the return type of all Jsx component functions is now constrained to Jsx.element, it makes sense that that's also what turns up when generating the interface.

@cknitt cknitt force-pushed the return-jsx-element branch 3 times, most recently from bbba8c4 to 1e83838 Compare October 9, 2025 18:06
@cknitt
Copy link
Member Author

cknitt commented Oct 9, 2025

@codex review

Copy link

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

@cknitt cknitt force-pushed the return-jsx-element branch from 1e83838 to 823a6de Compare October 9, 2025 18:16
@cknitt cknitt requested a review from zth October 9, 2025 19:38
let make = (type a, ~foo) => {
module T = unpack(foo: T with type t = a)
foo
React.null
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess there's no way to still return foo here, just wrapped in the relevant jsx element fn...?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only with Obj.magic I am afraid, if we wanted the JS output to stay the same.

Copy link
Member

@zth zth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just 1 small comment, but looks good!

@cknitt cknitt merged commit b2ce0f7 into rescript-lang:master Oct 10, 2025
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JSX PPX - add Jsx.element return constraint

2 participants