0

When using Typescript and passing an arrow function into another function as parameter, what would the type callout be?

My situation is with React components, and I'm trying to pass an activation function into a button component. With other such items I'll use an interface, but not sure how to type the param as being a callback function.

const activate = () => { // Activate edit function } export function EditButton({ activate }): SomeInterface { return ( <button className="wishButton" onClick={activate}>/</button> ); } 
2
  • { activate: () => void }
    – Phil
    CommentedDec 13, 2024 at 4:04
  • This question is similar to: Defining TypeScript callback type. If you believe it’s different, please edit the question, make it clear how it’s different and/or how the answers on that question are not helpful for your problem.
    – Phil
    CommentedDec 13, 2024 at 4:04

1 Answer 1

3
// Define the type of the activate callback function interface SomeInterface { activate: () => void; // This means 'activate' is a function that returns void } // Define the type of the activate callback function with an argument interface SomeInterface { activate: (id: number) => void; // function that takes a number as an argument } 

    Start asking to get answers

    Find the answer to your question by asking.

    Ask question

    Explore related questions

    See similar questions with these tags.