WEBVTT

00:00:00.000 --> 00:00:03.200
I believe that for most JavaScript

00:00:03.200 --> 00:00:06.400
developers, it makes sense to learn

00:00:06.400 --> 00:00:09.120
TypeScript and they probably should

00:00:09.120 --> 00:00:12.580
learn TypeScript, though, of course, I'll

00:00:12.580 --> 00:00:14.760
say it right away in case it isn't obvious,

00:00:15.380 --> 00:00:16.420
this is just my opinion.

00:00:16.680 --> 00:00:18.540
If you don't like TypeScript, you don't

00:00:18.540 --> 00:00:21.040
need to use or learn it, but I think there

00:00:21.040 --> 00:00:23.860
are good reasons for using or learning

00:00:23.860 --> 00:00:26.880
TypeScript and this is what I'll try to

00:00:26.880 --> 00:00:28.360
explain over the next minutes.

00:00:29.440 --> 00:00:32.540
And if I take a look at the numbers, the

00:00:32.540 --> 00:00:35.800
number of people working with

00:00:35.800 --> 00:00:38.600
TypeScript in the last Stack Overflow

00:00:38.600 --> 00:00:41.140
survey, for example, and the growth of

00:00:41.140 --> 00:00:45.120
that number, for example, then I would

00:00:45.120 --> 00:00:47.600
guess many people would agree.

00:00:47.860 --> 00:00:50.440
It's probably fair to assess that

00:00:50.440 --> 00:00:54.600
TypeScript is pretty popular and is

00:00:54.600 --> 00:00:57.420
growing in popularity because otherwise

00:00:57.420 --> 00:01:00.260
people would probably not be choosing

00:01:00.260 --> 00:01:04.160
it for their projects or at least it seems to

00:01:04.160 --> 00:01:06.160
offer substantial advantages.

00:01:06.820 --> 00:01:09.600
Now at the same time, I'm well aware

00:01:09.600 --> 00:01:15.680
that last year in 2023, we had a period in

00:01:15.680 --> 00:01:19.960
that year where some big projects were

00:01:19.960 --> 00:01:22.960
dropping TypeScript and we had a blog

00:01:22.960 --> 00:01:26.860
post by DHH, the creator of Ruby on

00:01:26.860 --> 00:01:31.000
Rails, who shared a pretty strong opinion

00:01:31.000 --> 00:01:34.100
against using TypeScript and why using

00:01:34.100 --> 00:01:35.340
TypeScript is bad.

00:01:36.220 --> 00:01:38.720
Now just to make sure that we're all on

00:01:38.720 --> 00:01:41.000
the same page, the idea behind

00:01:41.000 --> 00:01:43.380
TypeScript, the main idea, the main

00:01:43.380 --> 00:01:46.480
thing it brings to the table is, of course,

00:01:46.680 --> 00:01:49.960
that it adds static typing to JavaScript,

00:01:50.640 --> 00:01:53.340
which in the end means that when you

00:01:53.340 --> 00:01:56.780
are writing JavaScript code, you can't

00:01:56.780 --> 00:02:00.080
suddenly change the type of a value

00:02:00.080 --> 00:02:02.360
that's stored in a variable and you can

00:02:02.360 --> 00:02:05.820
also, for example, predefine the type that

00:02:05.820 --> 00:02:08.139
should eventually be stored in a variable.

00:02:08.680 --> 00:02:11.480
You can be clear about the type of value

00:02:11.480 --> 00:02:14.680
that's expected to be returned by some

00:02:14.680 --> 00:02:18.420
method or function and in general, the

00:02:18.420 --> 00:02:21.380
main idea simply is that you can be

00:02:21.380 --> 00:02:25.920
specific about which type of value goes

00:02:25.920 --> 00:02:28.800
where in your code and that you can't

00:02:28.800 --> 00:02:32.640
accidentally use the wrong type of value,

00:02:32.800 --> 00:02:33.500
for example.

00:02:34.360 --> 00:02:37.340
And it's not just about the wrong type,

00:02:37.700 --> 00:02:41.140
like a number being used in a place

00:02:41.140 --> 00:02:43.720
where a string is expected, though that

00:02:43.720 --> 00:02:44.600
can also be useful.

00:02:45.060 --> 00:02:47.660
It's also about the many places in

00:02:47.660 --> 00:02:50.520
JavaScript where a value might be

00:02:50.520 --> 00:02:54.300
undefined or null and you forgot about

00:02:54.300 --> 00:02:56.660
this scenario when writing your code

00:02:56.660 --> 00:02:59.300
and therefore suddenly your application,

00:02:59.460 --> 00:03:01.640
your website crashes when it's running

00:03:01.640 --> 00:03:05.380
in a certain scenario because such an

00:03:05.380 --> 00:03:08.000
undefined or null value was received.

00:03:08.440 --> 00:03:11.240
It's cases like this where TypeScript can

00:03:11.240 --> 00:03:14.140
help you because it makes you aware of

00:03:14.140 --> 00:03:16.480
such situations during development.

00:03:16.880 --> 00:03:20.580
It tells you if you are using a value in a

00:03:20.580 --> 00:03:22.680
certain place where it could potentially

00:03:22.680 --> 00:03:25.620
be undefined so that you can improve

00:03:25.620 --> 00:03:29.220
your code to handle that scenario where

00:03:29.220 --> 00:03:32.120
a certain value might be undefined and

00:03:32.120 --> 00:03:35.760
that can lead to better code, to code that

00:03:35.760 --> 00:03:38.660
contains fewer bugs and that hopefully

00:03:38.660 --> 00:03:41.980
doesn't crash at runtime that often.

00:03:42.400 --> 00:03:44.900
So TypeScript really brings some

00:03:44.900 --> 00:03:47.480
advantages to the table, at least in my

00:03:47.480 --> 00:03:50.400
opinion and as it seems, as I mentioned

00:03:50.400 --> 00:03:53.520
initially, also in the opinion of many

00:03:53.520 --> 00:03:54.260
other developers.

00:03:55.040 --> 00:03:57.280
Now at the same time we had for

00:03:57.280 --> 00:04:01.660
example dhh dropping TypeScript in his

00:04:01.660 --> 00:04:04.660
Turbo library because he complained

00:04:04.660 --> 00:04:07.760
about unnecessary type gymnastics

00:04:07.760 --> 00:04:11.040
being required when trying to write

00:04:11.040 --> 00:04:14.420
correct TypeScript code because that's

00:04:14.420 --> 00:04:15.600
also important.

00:04:16.180 --> 00:04:18.260
You can of course, when working with

00:04:18.260 --> 00:04:22.760
TypeScript, often take shortcuts and use

00:04:22.760 --> 00:04:26.620
the any type or the exclamation mark to

00:04:26.620 --> 00:04:29.480
tell TypeScript that you know that a

00:04:29.480 --> 00:04:32.860
certain value can't be undefined in that

00:04:32.860 --> 00:04:35.880
place where TypeScript thinks it could

00:04:35.880 --> 00:04:36.680
be undefined.

00:04:37.160 --> 00:04:40.920
You can use such shortcuts to avoid

00:04:40.920 --> 00:04:45.720
writing complex types or extra checks to

00:04:45.720 --> 00:04:48.120
rule out certain types.

00:04:48.760 --> 00:04:51.240
And it's especially that part where you

00:04:51.240 --> 00:04:54.120
sometimes might need to write complex

00:04:54.120 --> 00:04:57.520
types which typically means complex

00:04:57.520 --> 00:05:00.180
generic types which you really have to

00:05:00.180 --> 00:05:01.200
learn to get right.

00:05:02.000 --> 00:05:04.580
It's situations like this where you might

00:05:04.580 --> 00:05:07.840
feel inclined to drop TypeScript because

00:05:07.840 --> 00:05:11.820
yes, this can be complex and annoying

00:05:11.820 --> 00:05:16.100
and introduces a new error source

00:05:16.100 --> 00:05:18.620
because if you get a type wrong, you

00:05:18.620 --> 00:05:20.840
might start using it incorrectly and you

00:05:20.840 --> 00:05:23.800
might start using some value incorrectly

00:05:23.840 --> 00:05:26.140
and in the end it does have a pretty

00:05:26.140 --> 00:05:29.840
steep learning curve to be able to write

00:05:29.840 --> 00:05:31.240
good generic types.

00:05:31.420 --> 00:05:33.720
So yes, that can be annoying.

00:05:34.020 --> 00:05:37.940
However, this is mostly a problem library

00:05:37.940 --> 00:05:40.900
authors will face because if you are

00:05:40.900 --> 00:05:44.680
writing a library that's meant to be used

00:05:44.680 --> 00:05:48.020
by other developers in their projects, you

00:05:48.020 --> 00:05:50.500
might want to use TypeScript to help

00:05:50.500 --> 00:05:53.220
those developers in case they are using

00:05:53.220 --> 00:05:56.180
TypeScript in their projects so that your

00:05:56.180 --> 00:05:58.520
library gives them proper types and

00:05:58.520 --> 00:06:01.340
works properly in their library.

00:06:01.620 --> 00:06:03.100
So you might want to use TypeScript

00:06:03.100 --> 00:06:05.580
when writing your library and it's indeed

00:06:05.580 --> 00:06:08.800
in such situations where you often need

00:06:08.800 --> 00:06:10.620
to write complex types.

00:06:10.940 --> 00:06:13.360
And the reason for that is that if you're

00:06:13.360 --> 00:06:16.140
working on a project, not on a library,

00:06:16.780 --> 00:06:19.460
you often don't need super complex

00:06:19.460 --> 00:06:23.060
types because you can often rely on type

00:06:23.060 --> 00:06:25.740
inference and also because you don't

00:06:25.740 --> 00:06:29.220
need to write very generic abstract

00:06:29.220 --> 00:06:32.740
functions or value types that can be

00:06:32.740 --> 00:06:35.060
used in a broad variety of situations.

00:06:35.660 --> 00:06:37.840
Instead you often have one specific

00:06:37.840 --> 00:06:41.220
situation, one specific place in your code

00:06:41.220 --> 00:06:44.400
where a certain value is only used in one

00:06:44.400 --> 00:06:47.180
very specific way and therefore you don't

00:06:47.180 --> 00:06:49.400
need to set up a super flexible,

00:06:49.720 --> 00:06:52.680
complicated type to support all other

00:06:52.680 --> 00:06:54.280
kinds of value types.

00:06:54.560 --> 00:06:56.860
If you're building a library on the other

00:06:56.860 --> 00:06:58.980
hand, you typically need to do that

00:06:58.980 --> 00:07:02.340
because you want to offer flexibility in

00:07:02.340 --> 00:07:05.560
many places so that your library can be

00:07:05.560 --> 00:07:07.700
used in a broad variety of different

00:07:07.700 --> 00:07:08.300
projects.

00:07:09.040 --> 00:07:11.960
And therefore indeed if you are writing

00:07:11.960 --> 00:07:15.920
code for a library, you can have a hard

00:07:15.920 --> 00:07:18.340
time from time to time when working

00:07:18.340 --> 00:07:19.360
with TypeScript.

00:07:20.020 --> 00:07:23.160
Now I would argue it's probably still

00:07:23.160 --> 00:07:26.560
worth it because for one, your library

00:07:26.560 --> 00:07:28.920
being written in TypeScript of course

00:07:28.920 --> 00:07:31.060
also gets the benefits of using

00:07:31.060 --> 00:07:33.520
TypeScript, which for example means

00:07:33.520 --> 00:07:36.140
that certain errors can probably be

00:07:36.140 --> 00:07:37.880
caught early and fixed.

00:07:38.540 --> 00:07:40.580
It also means that your library might be

00:07:40.580 --> 00:07:43.100
more interesting for other developers

00:07:43.100 --> 00:07:45.460
who are using TypeScript in their

00:07:45.460 --> 00:07:46.240
projects.

00:07:46.720 --> 00:07:49.380
It might also help with collaboration and

00:07:49.380 --> 00:07:51.880
finding collaborators because whilst

00:07:51.880 --> 00:07:54.580
TypeScript could also be an extra hurdle,

00:07:55.060 --> 00:07:56.980
it might also mean that you're getting

00:07:56.980 --> 00:08:00.600
higher quality collaborators who help

00:08:00.600 --> 00:08:02.480
you working on the library.

00:08:02.900 --> 00:08:05.260
But of course ultimately, it is something

00:08:05.260 --> 00:08:08.000
that's totally up to the library author and

00:08:08.000 --> 00:08:11.340
I can fully understand if you don't feel

00:08:11.340 --> 00:08:14.260
like doing all those type gymnastics.

00:08:14.700 --> 00:08:17.500
Though the super important thing here

00:08:17.500 --> 00:08:21.280
really is that I'm now talking about

00:08:21.280 --> 00:08:22.220
libraries.

00:08:23.080 --> 00:08:25.320
As I mentioned before, if you are

00:08:25.320 --> 00:08:28.360
working on some project, on some web

00:08:28.360 --> 00:08:30.940
application, and you're just using some

00:08:30.940 --> 00:08:33.059
libraries but you're not writing one

00:08:33.059 --> 00:08:36.799
yourself, then chances are pretty high

00:08:36.799 --> 00:08:39.600
that you don't need to write a lot of

00:08:39.600 --> 00:08:40.740
complex types.

00:08:41.100 --> 00:08:44.260
You might sometimes need a bit of a

00:08:44.260 --> 00:08:47.480
more complex type here and there, but

00:08:47.480 --> 00:08:49.920
it's typically not too bad.

00:08:50.180 --> 00:08:52.680
Of course, always depending on the

00:08:52.680 --> 00:08:55.360
exact project you're working on, on the

00:08:55.360 --> 00:08:57.500
size of the project and so on.

00:08:57.820 --> 00:09:00.380
But chances are high that you won't

00:09:00.380 --> 00:09:03.480
have a too hard time when using

00:09:03.480 --> 00:09:05.520
TypeScript in such a project.

00:09:06.280 --> 00:09:08.600
And that's why I believe that every

00:09:08.600 --> 00:09:11.760
developer, library authors excluded to

00:09:11.760 --> 00:09:14.520
some extent, should really consider

00:09:14.520 --> 00:09:17.200
using TypeScript and learning

00:09:17.200 --> 00:09:20.080
TypeScript therefore because there are

00:09:20.080 --> 00:09:23.820
real benefits to be reaped and the price,

00:09:24.320 --> 00:09:26.740
if you're not one of those library authors,

00:09:26.960 --> 00:09:30.280
really isn't too high, in my opinion.

00:09:31.140 --> 00:09:33.800
And indeed, the opposite is the case, I

00:09:33.800 --> 00:09:34.320
would say.

00:09:34.840 --> 00:09:37.880
If you know how to work with TypeScript,

00:09:38.560 --> 00:09:42.340
you become more employable, both for

00:09:42.340 --> 00:09:46.000
a fixed employment position but also as

00:09:46.000 --> 00:09:46.780
a freelancer.

00:09:47.680 --> 00:09:49.360
Because if they're not using TypeScript,

00:09:49.780 --> 00:09:50.380
that's okay.

00:09:50.660 --> 00:09:52.800
You do know how to work with vanilla

00:09:52.800 --> 00:09:56.420
JavaScript after all, since TypeScript just

00:09:56.420 --> 00:09:57.380
builds up on that.

00:09:57.780 --> 00:10:00.360
But if they do use TypeScript, you have

00:10:00.360 --> 00:10:02.340
an advantage compared to developers

00:10:02.340 --> 00:10:03.120
who don't.

00:10:03.540 --> 00:10:06.820
So from that perspective, it also makes a

00:10:06.820 --> 00:10:09.720
lot of sense to learn TypeScript.

00:10:10.300 --> 00:10:13.600
The question then just is how good you

00:10:13.600 --> 00:10:15.180
have to become at TypeScript.

00:10:16.320 --> 00:10:19.140
You can definitely try to become a

00:10:19.140 --> 00:10:22.520
TypeScript master who's able to read

00:10:22.520 --> 00:10:24.860
and understand and most importantly

00:10:24.860 --> 00:10:28.060
write all the super complex generic

00:10:28.060 --> 00:10:29.980
types you might sometimes need in

00:10:29.980 --> 00:10:30.760
certain libraries.

00:10:31.480 --> 00:10:33.680
But chances are that that's not

00:10:33.680 --> 00:10:36.340
something you have to do because for

00:10:36.340 --> 00:10:37.900
all the reasons I mentioned before,

00:10:38.340 --> 00:10:40.540
where if you're not working on a library,

00:10:40.880 --> 00:10:43.660
you might not need those super

00:10:43.800 --> 00:10:45.760
complex generic types.

00:10:46.520 --> 00:10:49.420
Now of course, using TypeScript has one

00:10:49.420 --> 00:10:52.120
other disadvantage besides those

00:10:52.120 --> 00:10:54.180
complex types you sometimes need to

00:10:54.180 --> 00:10:54.520
write.

00:10:55.200 --> 00:10:58.480
And that disadvantage is that it's not

00:10:58.480 --> 00:11:01.300
running in the browser without an extra

00:11:01.300 --> 00:11:02.560
compilation step.

00:11:02.940 --> 00:11:05.680
So if you're writing TypeScript code, you

00:11:05.680 --> 00:11:09.500
can't just take that code and upload it to

00:11:09.500 --> 00:11:11.340
some server and call it a day.

00:11:12.000 --> 00:11:14.520
It will not work once it's been loaded

00:11:14.520 --> 00:11:16.900
into the browsers of your users.

00:11:17.580 --> 00:11:20.640
And as a side note, that's a bit different if

00:11:20.640 --> 00:11:23.620
you're using TypeScript for server side

00:11:23.620 --> 00:11:26.460
code, for example, because indeed there

00:11:26.460 --> 00:11:29.800
we have solutions like bun, which is a

00:11:29.800 --> 00:11:32.780
JavaScript and TypeScript runtime or

00:11:32.780 --> 00:11:36.020
extra packages that indeed do allow you

00:11:36.020 --> 00:11:39.340
to execute TypeScript code just like that

00:11:39.340 --> 00:11:41.380
without a compilation step.

00:11:41.980 --> 00:11:43.920
But if you're writing client-side

00:11:43.920 --> 00:11:46.880
JavaScript code, it won't work just like

00:11:46.880 --> 00:11:47.220
that.

00:11:47.480 --> 00:11:49.200
And that of course can be a

00:11:49.200 --> 00:11:51.960
disadvantage if you have maybe a pretty

00:11:51.960 --> 00:11:54.760
simple project, which otherwise

00:11:54.760 --> 00:11:59.340
wouldn't require a compilation step and

00:11:59.340 --> 00:12:01.980
wouldn't require a build tool that

00:12:01.980 --> 00:12:04.300
compiles your code and optimizes your

00:12:04.300 --> 00:12:04.660
code.

00:12:05.320 --> 00:12:08.040
Or then you still need one because

00:12:08.040 --> 00:12:09.040
you're using TypeScript.

00:12:09.640 --> 00:12:12.320
So that need for that extra compilation

00:12:12.320 --> 00:12:15.420
step and build step, that of course can

00:12:15.420 --> 00:12:17.420
be annoying in certain situations.

00:12:18.180 --> 00:12:22.340
Now again, my feeling here is, and what

00:12:22.340 --> 00:12:26.440
I see out there, that for many projects,

00:12:26.620 --> 00:12:29.640
probably most projects, front-end

00:12:29.640 --> 00:12:33.300
JavaScript projects, you have a build tool

00:12:33.300 --> 00:12:35.320
and a build step anyways.

00:12:35.740 --> 00:12:37.740
You're using something like Vite or

00:12:37.740 --> 00:12:39.400
Webpack anyways.

00:12:40.120 --> 00:12:44.180
And then adding TypeScript shouldn't

00:12:44.180 --> 00:12:47.100
be a huge deal, to be honest, because

00:12:47.100 --> 00:12:49.120
you have that process anyways.

00:12:49.580 --> 00:12:51.960
Why not just add in that compilation

00:12:51.960 --> 00:12:52.640
step?

00:12:52.780 --> 00:12:55.420
Typically it shouldn't be too complicated.

00:12:56.320 --> 00:12:59.240
So that might be a reason for some

00:12:59.240 --> 00:12:59.720
people.

00:13:00.240 --> 00:13:03.140
For example, it was a reason for the

00:13:03.140 --> 00:13:05.940
Svelte team, which also dropped

00:13:05.940 --> 00:13:09.780
TypeScript and moved to JS docs, which

00:13:09.780 --> 00:13:11.900
is another way of adding types that does

00:13:11.900 --> 00:13:15.560
not require a build step, but also isn't as

00:13:15.560 --> 00:13:17.080
ergonomic in my opinion.

00:13:17.920 --> 00:13:20.540
But it's probably not an argument for

00:13:20.540 --> 00:13:22.540
many other developers who have a build

00:13:22.540 --> 00:13:24.540
step, who have a build tool in their

00:13:24.540 --> 00:13:27.300
project anyways, because there it really

00:13:27.300 --> 00:13:28.600
doesn't matter too much.

00:13:28.760 --> 00:13:30.760
Typically compilation also doesn't take

00:13:30.760 --> 00:13:31.520
super long.

00:13:32.160 --> 00:13:34.320
And of course, as I mentioned, we also

00:13:34.320 --> 00:13:36.360
have situations where you might not

00:13:36.360 --> 00:13:39.280
need one at all despite using TypeScript.

00:13:39.400 --> 00:13:42.100
If you are, for example, executing your

00:13:42.100 --> 00:13:45.120
code with a tool or in an environment

00:13:45.120 --> 00:13:47.960
that natively supports TypeScript,

00:13:48.240 --> 00:13:50.560
though there you always might want to

00:13:50.560 --> 00:13:53.720
at least question whether you possibly

00:13:53.720 --> 00:13:56.180
could have a performance disadvantage

00:13:56.180 --> 00:13:58.440
by running uncompiled TypeScript.

00:13:58.620 --> 00:14:00.900
That could be a valid concern there and

00:14:00.900 --> 00:14:02.960
is something you should definitely check

00:14:02.960 --> 00:14:05.020
and make sure that it isn't.

00:14:05.080 --> 00:14:08.340
But for all those reasons, I do believe

00:14:08.340 --> 00:14:11.820
that most developers should learn and

00:14:11.820 --> 00:14:14.260
use TypeScript because learning it

00:14:14.260 --> 00:14:17.980
honestly isn't too complicated if you

00:14:17.980 --> 00:14:20.580
don't get into those super complex

00:14:20.580 --> 00:14:21.940
types, at least initially.

00:14:22.760 --> 00:14:25.080
And therefore, then you just get a lot of

00:14:25.080 --> 00:14:28.140
benefits, in my opinion, without too

00:14:28.140 --> 00:14:29.640
much extra work.

00:14:29.940 --> 00:14:32.540
And indeed, once you've worked with

00:14:32.540 --> 00:14:35.200
TypeScript a bit, you will see that

00:14:35.200 --> 00:14:38.500
actually you don't have to add too many

00:14:38.500 --> 00:14:40.800
types in your code base because often

00:14:40.800 --> 00:14:43.700
you can rely on type inference anyways,

00:14:44.380 --> 00:14:46.520
and then you just get the benefits

00:14:46.520 --> 00:14:50.180
almost without any additional extra

00:14:50.180 --> 00:14:50.620
work.

00:14:51.240 --> 00:14:53.640
And that's why I personally love

00:14:53.640 --> 00:14:55.720
TypeScript and why I'm using it in

00:14:55.720 --> 00:14:59.260
essentially all my projects and why I

00:14:59.260 --> 00:15:01.540
recommend the same for most other

00:15:01.540 --> 00:15:02.080
developers.