@@ -107,6 +107,7 @@ type type_clash_context =
107107 is_constant : string option ;
108108 }
109109 | FunctionArgument of {optional : bool ; name : string option }
110+ | JsxComponent
110111 | BracedIdent
111112 | Statement of type_clash_statement
112113 | ForLoopCondition
@@ -127,6 +128,7 @@ let context_to_string = function
127128 | Some TryReturn -> " TryReturn"
128129 | Some StringConcat -> " StringConcat"
129130 | Some (FunctionArgument _ ) -> " FunctionArgument"
131+ | Some JsxComponent -> " JsxComponent"
130132 | Some ComparisonOperator -> " ComparisonOperator"
131133 | Some IfReturn -> " IfReturn"
132134 | Some TernaryReturn -> " TernaryReturn"
@@ -145,6 +147,7 @@ let error_type_text ppf type_clash_context =
145147 | Some ArrayValue -> " This array item has type:"
146148 | Some (SetRecordField _ ) ->
147149 " You're assigning something to this field that has type:"
150+ | Some JsxComponent -> " This JSX tag resolves to:"
148151 | _ -> " This has type:"
149152 in
150153 fprintf ppf " %s" text
@@ -162,6 +165,7 @@ let error_expected_type_text ppf type_clash_context =
162165 | None -> () );
163166
164167 fprintf ppf " is expecting:"
168+ | Some JsxComponent -> fprintf ppf " But JSX component positions require:"
165169 | Some ComparisonOperator ->
166170 fprintf ppf " But it's being compared to something of type:"
167171 | Some SwitchReturn -> fprintf ppf " But this switch is expected to return:"
@@ -396,6 +400,17 @@ let print_extra_type_clash_help ~extract_concrete_typedecl ~env loc ppf
396400 \ - Remove the @{<info>await@} if this is not expected to be a promise\n \
397401 \ - Wrap the expression in @{<info>Promise.resolve@} to convert the \
398402 expression to a promise"
403+ | Some JsxComponent , _ ->
404+ fprintf ppf
405+ " \n\n \
406+ \ JSX tags must resolve to a React component, not a plain function.\n\n \
407+ \ Possible solutions:\n \
408+ \ - If this function takes labeled props, annotate it with \
409+ @{<info>@react.component@}\n \
410+ \ - If this function takes a single props record, annotate it with \
411+ @{<info>@react.componentWithProps@}\n \
412+ \ - If this is already a valid component-like value, wrap it with \
413+ @{<info>React.component(...)@}"
399414 | Some IfReturn , _ ->
400415 fprintf ppf
401416 " \n\n \
0 commit comments