I am creating the same project Mosh creates in the React course part 1 but I do not understand a lot of things
Type definition as a general type that has not been defined. For example if i want my data to look a certain way but i’m not sure yet what it should look-like, i use t then change it later when i know.
But we could use any type why to complicate stuff with things not logical.
Well lets say you have a function which only does a x b that works fine if a= 2 and b= 3. However lets say you get some data and it’s a = “cat” b= 3
You can’t do cat x 3 and get 3 cats you have a string and a number. So it’d be nice to declare in your function numbers only, and you get an error if you try to pass a string. Saves the trouble of not knowing why it won’t work.
It gets more complex when you want an array of objects ex [ {name: “john”, age: 30}, {name: “jane”, age 32}] you’d want to make sure whatever you do with the data is being sent to the right place, and if there is an error you might know the data got saved wrong and needs to be fixed.
Bottom line it’s so we can find errors faster, and run tests to find issues to rule out things like type errors, to focus on implementation.