SolidJSS
SolidJSโ€ข2y ago
var

Binding events in a typesafe way with typescript?

I'm following the binding events (https://docs.solidjs.com/concepts/components/event-handlers#binding-events) section of the docs so solid can optimize my event handlers, but I'm not able to do this in a typesafe way. For example:

function square(number: number, event: Event) {
  const squaredNumber = number * number;
  console.log(`${number} squared is ${squaredNumber}`);
}

// no type error here, which I would expect since I'm passing a string as an argument that should be a number:
const Example = () => (
  <button onClick={[square, "not a number"]}>click here</button>  
);


Is there any way to take advantage of Solid's event binding pattern while still retaining typesaftey?
Was this page helpful?