Typescript – type checking
Fiquring out what is the most basic thing to use typescript for when moving for normal javascript or ES6. Checking to see if the type declare is correct is vital as it would help with errors that arise.
An example would be a Gatsby component which is doing a GraphQL call and passing that data in to a React component. The data from the query can be in the form of an array or object and catching these errors would be useful.
Converting from typescript to normal javascript
Type check the code to see if it’s correct. In the first example it works but in the second it catches the wrong type and alarms an error.
Changing the data1 variable to the correct type will solve for the issue.
Opting Out
Opting out of type checking so that it passes without any error. It may be needed in your code as you may be unsure what type it would be and therefore leaving it as :any is most useful.
Inferface
Using Interface to type check when passing parameters into a function and ensure that it checks that the right types are passed through.