diff --git a/CHANGELOG.md b/CHANGELOG.md index 4272471bd2..16246e9cdf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ #### :nail_care: Polish +- Improve error message when passing `children` prop to a component that doesn't accept it. https://github.com/rescript-lang/rescript-compiler/pull/7044 - Improve error messages for pattern matching on option vs non-option, and vice versa. https://github.com/rescript-lang/rescript-compiler/pull/7035 - Improve bigint literal comparison. https://github.com/rescript-lang/rescript-compiler/pull/7029 - Improve output of `@variadic` bindings. https://github.com/rescript-lang/rescript-compiler/pull/7030 diff --git a/jscomp/build_tests/super_errors/expected/component_missing_prop_children.res.expected b/jscomp/build_tests/super_errors/expected/component_missing_prop_children.res.expected new file mode 100644 index 0000000000..e2f42fd177 --- /dev/null +++ b/jscomp/build_tests/super_errors/expected/component_missing_prop_children.res.expected @@ -0,0 +1,11 @@ + + We've found a bug for you! + /.../fixtures/component_missing_prop_children.res:6:35-42 + + 4 │ type props<'name> = {name: 'name} + 5 │ + 6 │ let make = (): props<'name> => {children: ""} + 7 │ } + 8 │ + + This JSX component does not accept child elements. It has no children prop \ No newline at end of file diff --git a/jscomp/build_tests/super_errors/fixtures/component_missing_prop_children.res b/jscomp/build_tests/super_errors/fixtures/component_missing_prop_children.res new file mode 100644 index 0000000000..e248742d88 --- /dev/null +++ b/jscomp/build_tests/super_errors/fixtures/component_missing_prop_children.res @@ -0,0 +1,7 @@ +// Since the React transform isn't active in the tests, mimic what the transform outputs. +module Component = { + @res.jsxComponentProps + type props<'name> = {name: 'name} + + let make = (): props<'name> => {children: ""} +} diff --git a/jscomp/ml/error_message_utils.ml b/jscomp/ml/error_message_utils.ml index d178f2129f..23891716e9 100644 --- a/jscomp/ml/error_message_utils.ml +++ b/jscomp/ml/error_message_utils.ml @@ -278,8 +278,13 @@ let print_component_name ppf (p : Path.t) = let print_component_wrong_prop_error ppf (p : Path.t) (_fields : Types.label_declaration list) name = fprintf ppf "@["; - fprintf ppf - "@[<2>The prop @{%s@} does not belong to the JSX component " name; + (match name with + | "children" -> + fprintf ppf + "@[<2>This JSX component does not accept child elements. It has no @{children@} prop " + | _ -> + fprintf ppf + "@[<2>The prop @{%s@} does not belong to the JSX component " name); print_component_name ppf p; fprintf ppf "@]@,@,"