Skip to content

Commit 98c8cb4

Browse files
committed
note that you need to unwrap options in JSX
1 parent 8d3c011 commit 98c8cb4

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

compiler/ml/error_message_utils.ml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,10 @@ let print_extra_type_clash_help ~extract_concrete_typedecl ~env loc ppf
259259
"@,\
260260
@,\
261261
Possible solutions: @,\
262-
- Rewrite the object to a record, like: @{<info>%s@}@,"
262+
- Rewrite the object to a record%s@{<info>%s@}@,"
263+
(match suggested_rewrite with
264+
| Some _ -> ", like: "
265+
| None -> "")
263266
(match suggested_rewrite with
264267
| Some rewrite -> rewrite
265268
| None -> "")
@@ -312,6 +315,15 @@ let print_extra_type_clash_help ~extract_concrete_typedecl ~env loc ppf
312315
print_jsx_msg "string" (with_configured_jsx_module "string")
313316
| _ when Path.same p Predef.path_float ->
314317
print_jsx_msg "float" (with_configured_jsx_module "float")
318+
| [_] when Path.same p Predef.path_option ->
319+
fprintf ppf
320+
"@,\
321+
@,\
322+
You need to unwrap this option to its underlying value first, then \
323+
turn that value into a JSX element.@,\
324+
For @{<info>None@}, you can use @{<info>%s@} to output nothing into \
325+
JSX.@,"
326+
(with_configured_jsx_module "null")
315327
| [tp] when Path.same p Predef.path_array && is_jsx_element tp ->
316328
print_jsx_msg
317329
~extra:
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
We've found a bug for you!
3+
/.../fixtures/jsx_type_mismatch_option.res:17:13-16
4+
5+
15 │ }
6+
16 │
7+
17 │ let x = <> {None} </>
8+
18 │
9+
10+
This has type: option<'a>
11+
But it's expected to have type: React.element (defined as Jsx.element)
12+
13+
You need to unwrap this option to its underlying value first, then turn that value into a JSX element.
14+
For None, you can use React.null to output nothing into JSX.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
@@config({
2+
flags: ["-bs-jsx", "4"],
3+
})
4+
5+
module React = {
6+
type element = Jsx.element
7+
type componentLike<'props, 'return> = 'props => 'return
8+
type component<'props> = Jsx.component<'props>
9+
10+
@module("react/jsx-runtime")
11+
external jsx: (component<'props>, 'props) => element = "jsx"
12+
13+
type fragmentProps = {children?: element}
14+
@module("react/jsx-runtime") external jsxFragment: component<fragmentProps> = "Fragment"
15+
}
16+
17+
let x = <> {None} </>

0 commit comments

Comments
 (0)