How do I get an integer in the CustomeEventData of the button ClickEvents?

I tried the following code.
Here, I enter “1” in CustomeEventData and call the following event from the button.

clickEvent(event: Event, num: number) {
    log(num);
}

However, this is not desirable.
This is because I am asking for an integer, not a float.

If I try the following, I get an error
clickEvent(event: Event, num: integer)

The error message
「 ‘integer’ refers to a value, but is used here as a type.’ Did you intend ‘typeof integer’? ts(2749)」

I do not understand what this means. I just want to receive an integer (int).

In js/ts, there is no integer or float. There is only one numerical type “number”. So, code like this num: integer is illegal, except you defined your own integer.

And CustomeEventData actually is a string.


image

You can use Number(strNum) or parseFloat(strNum) to convert a string to a number.And you can use paseInt(strNum) to convert a float string to a interger number, it can convert float number to interger number too.
image

1 Like

I see. Thank you very much!