It's just JavaScript with Super Power
TypeScript reduces the number of unit tests you need to write
One of the first reasons I see is the insane gain of time when it comes to testing your code. If you wrote any tests at all before, you can count on a 10–20% decrease on how many you have to write. If you didn’t, then you gain those extra 20% at no cost!
React Docs : Handling Events | SyntheticEvent
I still remember the time when to define a function to handle an event, was just write it...
Now I need to figure it out which type should I use...
TIP: use the IntelliSense power, do a mouse hover on top of onClick
In summary: the bad and most difficult part is, learn which types should be used with React.
To help with that, follow some useful links:
A project without TypeScript
A project with TypeScript
More useful links:
Learn more: testingjavascript.com
TypeScript
Jest
TypeScript
Catch typos and type errors as you write the code.
Normally, you need to write unit test cases to check if the values passed are like the expected.
Using the TypeScript on your project, you avoid the need to write that kind of unit test.
Jest
Verify that individual, isolated parts work as expeted.
Jest - is a JavaScript Testing Framework, it provides a set of tools to help write and execute unit tests.
Take a look at the documentation and API.
Jest Configs
// jest.config.js
module.exports = {
...
// it will look for the testing files with the
// given pattern
testMatch: [
"**/__tests__/**/*.[jt]s?(x)",
"**/?(*.)+(spec|test).[jt]s?(x)"
],
...
};
Or defining a configuration file (it should be placed on the project root directory).
You can use it with CLI commands
jest
jest path/to/my-test.js
...
Jest
A project without TypeScript
Jest
A project with TypeScript
Jest
As you can check from the given examples
using TypeScript on your project you'll be ending writing less code
to be sure that the code will do what you want
Jest
Jest
Useful links: