Type number is not assignable to type "string"

$w . onReady ( function () {
let lapelPinCostEach = 4 ;

  $w ( '#lapelPinQtyCombo' ). onChange (( event )=>{ 
   let  lapelPinQtyComboValue  =  event . target . value ; 
   let  totalPinCost  =  lapelPinQtyComboValue  *  lapelPinCostEach ; 
   console . log ( "total pin cost:::::::::::::"  + totalPinCost ); 
   console . log ( "type is: "  +  $w ( '#lapelPinTotalCost' ). type ); 
   $w ( '#lapelPinTotalCost' ). value  =  totalPinCost ; 
}) 

});

============ FORM =================================

==============Content Manager =====================

Why am I getting the subject error noting that my ‘lapelPinTotalCost’ is a string when I have it all set to number?

This is the error line:
$w ( ‘#lapelPinTotalCost’ ). value = totalPinCost ;
String number

Thank you!
Ed

I would use this to check and see what is the type of the variable. If it is a string you can convert it to a number then it should work

console.log(typeof totalPinCost);

The error states that it is a number

totally read that backwards. Sometimes I interchange words when reading too fast. I would reach out to support to open a ticket and investigate if you have encountered a bug https://support.wix.com/en/article/contacting-wix-customer-care-for-support

Thanks. I would suspect this has come up before. It’s hard to believe this has not happened to anyone else.

I think I know what is going on here. If you used the text input, the type is always a string.

Setting the input type does not change this, it only restricts what the user can enter into the input from the front end.

See the bottom of this screenshot from the docs. I will pass along to the docs team that this may not be intuitive.

If you set the value as a string after you calculate, it should set as expected

https://www.wix.com/velo/reference/$w/textinput/inputtype

Thank you. This fixed it!!