DEV Community

A beginner guide switching from javasctipt to typescript.

Princewhyte Dabotubo on July 31, 2022

One morning I woke up and the new technical wave is that I should use typescript instead of javascript. Okay, wait do you mean I have to start lea...
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
 
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

Collapse
 
marvel_at_don profile image
Marvellous D. Amos

I understand thanks

Collapse
 
marvel_at_don profile image
Marvellous D. Amos

thanks for this Mr. white
I recently had to switch from javascript to typescript and I had indeed been considering learning typescript as a course.
Even when I began using it, looking at this, I realize I have neglected to understand the major disparity between both languages as well as their syntax

Collapse
 
princewhyte2 profile image
Princewhyte Dabotubo

Thanks for your comment.
I'm aware of you not typing everything.
It's jut to show what typing is in typescript to beginners. Thanks for the great comments.