DEV Community

Discussion on: A beginner guide switching from javasctipt to typescript.

Collapse
 
marvel_at_don profile image
Marvellous D. Amos

Although I would like to ask since the language intends for the developer to be intentional, what about cases where the developer cannot account for the data type from users' input?

say a form field designated as an array where the user is free to input either a string, number etc.

Collapse
 
princewhyte2 profile image
Princewhyte Dabotubo

Inputs are strings. For you to do anything with them in other data types you have to cast them (convert).

Collapse
 
marvel_at_don profile image
Marvellous D. Amos

I understand thanks

Collapse
 
syeo66 profile image
Red Ochsenbein (he/him)

Or even better. Properly validate the input to make sure the value is in the correct type.

Thread Thread
 
marvel_at_don profile image
Marvellous D. Amos

thanks.
I'll try it