-
Notifications
You must be signed in to change notification settings - Fork 463
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
Type mis-match in destructuring of @optional field #5472
Comments
Not sure what's in the comments is accurate: in the |
// definition
type props<'name> = { @optional name: 'name } // 1
let make = ({ name }: props<_>) => name->Belt.Option.getWithDefault("")->React.string // 2
// application
React.createElement(Foo.make, {name: "Foo"}) // Error, wanted: option<string> I encountered this issue when I write the jsx ppx v4. The // correct
<Foo name="Foo">
// wrong
<Foo name=Some("Foo") /> |
What's the original component definitions? Looks like this is what was intended: module Foo = {
// definition
type props<'name> = {@optional name: 'name} // 1
let make = ({name: @optional name}: props<_>) => name->Belt.Option.getWithDefault("")->React.string // 2
} |
The original definition is below. @react.component
let make = (~name=?) => {
<div> {name->Belt.Option.getWithDefault("")->React.string} </div>
} |
{name: @optional name}: props<_> This would work, unless the refmt removes the type annotation. I'll fix the ppx v4 accordingly. |
Back to the first example, can user add the type annotation in this case? At least, when they want. type t0 = {@optional x: int}
let f0: t0 = {x: 1}
let {x: @optional x} = f0 // add type annotation |
Yes I've noticed the issue with formatting, will bring it to the syntax repo. And then to the editor repo which vendors it. |
Yes they can write type annotations. |
Checked! rescript-lang/syntax#582 |
The issue about formatting: rescript-lang/syntax#583 |
This is related #5423 #5452
I think there's a type mis-match after destructuring. Isn't it correct that type of x is
option<int>
?The text was updated successfully, but these errors were encountered: