TypeScript is testing - a podcast by Kent C. Dodds

from 2021-05-20T14:59:40

:: ::

https://kcd.im/trophy
https://kentcdodds.com/blog/eliminate-an-entire-category-of-bugs-with-a-few-simple-toolsTypeScript is tests. Tests are type script. So type script is just a way to
give yourself more confidence. Sure, it helps you in your workflow, itmakes you a faster as you're developing because you have autocomplete and
stuff like that. And testing does the same thing as well as yourefactoring, you know that you didn't break anything you get a much faster
feedback when you you're running your tests as you're working on things.
And both of these also make the initial code take longer. So it takes moretime to think.About the types that you're writing takes more time to
actually write the tests. And they can also be an enormous time sink whereyou spend a ton of time working on a task or a ton of time working on the
on the types and then you've later realized that you don't need that code
at all so you just throw all that work away.So, I I find that typescript and testing are way more related than they are
or similar than they are different. And I think this is a good thingthough, the whole goal is to be more confident in the changes that
were.Making in the application that were shipping. And the cool thing aboutTypeScript is that it eliminates an entire category of bugs.
I actually have a blog post about that. And it also eliminates an entirecategory of tests, which you're probably not writing but maybe you should.
So one of the things about code coverage is that it doesn't what we really
actually need is data coverage or use case coverage because you may have afunction called ad that accepts two numbers and add.
S them together and you could write a couple of tests for that if youwanted to but you're probably not writing like it's not very normal for
people to write a test that says what happens if I pass a string whathappens if I pass a boolean but you know, what a you might have a test that
says what happens if I don't pass the arguments or something and because
there are some defaults.But and that and because there are defaults you're going to want to cover
that. But we've very often don't do a whole lot of defensive programming
and runtime and type assertions of.You know, what the arguments that werepassed? Maybe you do that for some of your functions, but probably not all.
And so you can you don't get a much confidence in in that aspect. And you
you could but it's just way easier to just use a type to language like
TypeScript and then that entire category of bugs in the entire category oftests don't need to be written. So type script is tests.

Further episodes of 3 Minutes with Kent

Further podcasts by Kent C. Dodds

Website of Kent C. Dodds