rescript-compiler icon indicating copy to clipboard operation
rescript-compiler copied to clipboard

No warning on unused but initialised parameters in React components

Open remitbri opened this issue 1 year ago • 2 comments

When declaring a React component, unused but initialised parameters don't get the warning flag "unused variable xxx"

@react.component
let make = (
  ~unused1,    // unused variable unused1.
  ~unsused2=true, 
  ~unused3=?,    // unused variable unused3.
  ~text=?
) => {
  <div> {React.string(text->Option.getOr(""))} </div>
}

If it's a "regular" function, the same parameter gets the warning

let foo = (
  ~unused1,   // unused variable unused1.
  ~unsused2=true,   // unused variable unsused2.
  ~unused3=?,    // unused variable unused3.
  ~text=?) =>
 text->Option.getOr("")

Using the playground, it seems the bug appeared with v10.1.2 and is still there for v11.x and v12.x

remitbri avatar Sep 18 '24 15:09 remitbri

I believe this is because the JSX v4 emits a switch for the default param case, although not sure. cc @mununki

zth avatar Sep 18 '24 17:09 zth

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

github-actions[bot] avatar Sep 15 '25 02:09 github-actions[bot]