WEBVTT

00:00:00.280 --> 00:00:02.230
TypeScript is built directly into Elements.

00:00:02.340 --> 00:00:03.740
It type checks your code for the server

00:00:03.760 --> 00:00:04.710
and the browser.

00:00:04.940 --> 00:00:06.660
A new source graph with layers makes

00:00:06.680 --> 00:00:07.930
that really fast.

00:00:08.380 --> 00:00:09.060
Your editor,

00:00:09.080 --> 00:00:11.250
terminal and agent get the same errors,

00:00:11.300 --> 00:00:12.310
in microseconds.

00:00:12.960 --> 00:00:15.210
This function, greet, takes a string.

00:00:15.520 --> 00:00:16.670
I pass it a number.

00:00:17.000 --> 00:00:17.920
That's a type error,

00:00:17.940 --> 00:00:19.950
and my editor underlines the number.

00:00:20.250 --> 00:00:20.950
I save,

00:00:21.120 --> 00:00:23.170
and the Elements build server runs a build.

00:00:23.680 --> 00:00:25.120
The build server type checks the file

00:00:25.140 --> 00:00:27.350
and reports the type error in my terminal.

00:00:27.920 --> 00:00:29.100
An agent runs this command

00:00:29.120 --> 00:00:31.130
to read the errors from the last build.

00:00:31.420 --> 00:00:33.240
The build server returns the same error,

00:00:33.260 --> 00:00:34.410
in microseconds.

00:00:34.800 --> 00:00:36.460
One program, the build server,

00:00:36.480 --> 00:00:37.900
sent that error to my editor,

00:00:37.920 --> 00:00:39.810
my terminal and the agent's command.

00:00:40.020 --> 00:00:41.360
The agent's command didn't run

00:00:41.380 --> 00:00:42.610
the type checker again.

00:00:42.720 --> 00:00:44.160
It asked the build server for the errors

00:00:44.180 --> 00:00:45.370
from the last build.

00:00:45.410 --> 00:00:47.150
I change the number back to a name,

00:00:47.170 --> 00:00:48.000
and save.

00:00:48.260 --> 00:00:50.040
My editor removes the underline.

00:00:50.090 --> 00:00:51.120
The build is ok,

00:00:51.210 --> 00:00:53.080
and the agent's command returns ok.

00:00:53.690 --> 00:00:55.290
In most TypeScript projects, your editor

00:00:55.310 --> 00:00:57.220
starts its own TypeScript server.

00:00:57.570 --> 00:00:59.420
Your agent runs tsc.

00:00:59.850 --> 00:01:01.460
It type checks every file,

00:01:01.550 --> 00:01:02.580
and your agent waits.

00:01:02.940 --> 00:01:04.840
Your bundler removes the type annotations

00:01:04.860 --> 00:01:05.990
and writes JavaScript.

00:01:06.360 --> 00:01:08.210
It doesn't type check your code at all.

00:01:08.700 --> 00:01:11.450
And your CI system runs tsc again.

00:01:11.560 --> 00:01:12.480
I designed Elements

00:01:12.500 --> 00:01:14.790
to have one program type check your code:

00:01:14.840 --> 00:01:15.650
the build server.

00:01:15.830 --> 00:01:18.530
I add a function that sorts a list of names.

00:01:18.660 --> 00:01:19.890
It calls toSorted,

00:01:19.980 --> 00:01:22.810
which was added to JavaScript in ES2023.

00:01:23.020 --> 00:01:23.720
I save.

00:01:23.920 --> 00:01:25.830
The build server reports a type error.

00:01:26.240 --> 00:01:29.070
toSorted does not exist on a string array.

00:01:29.330 --> 00:01:31.440
The last line of that error says browser.

00:01:31.930 --> 00:01:33.310
This file runs on the server

00:01:33.330 --> 00:01:34.430
and in the browser.

00:01:34.450 --> 00:01:35.870
So Elements type checks it twice:

00:01:35.890 --> 00:01:36.770
once for the server,

00:01:36.790 --> 00:01:38.240
and once for the browser.

00:01:38.570 --> 00:01:40.390
The toSorted call has no error

00:01:40.410 --> 00:01:41.250
for the server.

00:01:41.270 --> 00:01:43.180
It's an error for the browser only.

00:01:43.510 --> 00:01:45.780
An Elements project has no tsconfig.

00:01:46.270 --> 00:01:49.060
You set TypeScript options in config.jsoc.

00:01:49.410 --> 00:01:50.870
JSOC is our config language.

00:01:50.890 --> 00:01:52.710
It has comments, identifier keys,

00:01:52.730 --> 00:01:54.420
an env function and build tags.

00:01:54.590 --> 00:01:56.090
This file sets lib,

00:01:56.160 --> 00:01:58.030
the list of library types, twice.

00:01:58.480 --> 00:01:59.240
The first lib line

00:01:59.260 --> 00:02:01.630
is the server's value, ES2023.

00:02:01.880 --> 00:02:03.640
The comment above the second lib line

00:02:03.660 --> 00:02:05.550
has a build tag: at browser.

00:02:05.960 --> 00:02:07.080
So the second lib line

00:02:07.100 --> 00:02:09.410
is the browser's value, ES2020.

00:02:09.790 --> 00:02:11.790
So the server's lib declares toSorted,

00:02:11.810 --> 00:02:13.720
and the browser's lib does not.

00:02:13.820 --> 00:02:15.660
The agent's command prints the same error,

00:02:15.680 --> 00:02:17.120
and the field named targets

00:02:17.140 --> 00:02:18.890
has one value: browser.

00:02:19.170 --> 00:02:21.120
I delete the function, and save.

00:02:21.310 --> 00:02:22.340
The build is ok.

00:02:22.890 --> 00:02:24.370
The build server also type checks

00:02:24.390 --> 00:02:26.860
the TypeScript in our reactive HTML files.

00:02:27.190 --> 00:02:28.560
This file is the home page,

00:02:28.580 --> 00:02:30.590
and this expression prints the greeting.

00:02:31.020 --> 00:02:32.850
I misspell greeting, and save.

00:02:33.180 --> 00:02:35.190
The error asks: did you mean greeting?

00:02:35.500 --> 00:02:36.480
The same type checker

00:02:36.500 --> 00:02:37.980
that checks TypeScript files found

00:02:38.000 --> 00:02:40.290
that error, in a reactive HTML file.

00:02:40.580 --> 00:02:42.930
My editor underlines the misspelled name.

00:02:43.200 --> 00:02:44.680
My terminal and the agent's command

00:02:44.700 --> 00:02:45.970
print the same error.

00:02:46.300 --> 00:02:47.910
I fix the spelling, and save.

00:02:48.040 --> 00:02:49.010
The build is ok.

00:02:49.550 --> 00:02:50.450
The build server reads

00:02:50.470 --> 00:02:51.950
each source file once,

00:02:51.970 --> 00:02:54.360
parses it once and resolves its imports.

00:02:54.430 --> 00:02:55.700
It keeps the parsed files

00:02:55.720 --> 00:02:57.570
and resolved imports in memory.

00:02:57.820 --> 00:02:58.970
That's the source graph.

00:02:59.480 --> 00:03:01.280
In this tree, a parent file imports

00:03:01.300 --> 00:03:03.050
the child files under it.

00:03:03.400 --> 00:03:05.800
After a save, Elements type checks the file

00:03:05.820 --> 00:03:07.210
that you changed.

00:03:07.290 --> 00:03:09.230
If that file has a new export,

00:03:09.250 --> 00:03:11.100
or an export with a different type,

00:03:11.190 --> 00:03:13.700
Elements also type checks its parent files.

00:03:13.830 --> 00:03:15.590
It stops at the first parent file

00:03:15.610 --> 00:03:17.440
whose exports didn't change.

00:03:17.650 --> 00:03:18.770
For every other file,

00:03:18.790 --> 00:03:19.690
Elements keeps the errors

00:03:19.710 --> 00:03:20.900
from the last build.

00:03:20.950 --> 00:03:22.490
So a build after a save

00:03:22.510 --> 00:03:23.900
takes a few milliseconds.

00:03:24.730 --> 00:03:26.060
The source graph has layers.

00:03:26.610 --> 00:03:28.620
Layer zero is the files on disk.

00:03:28.910 --> 00:03:30.470
Your editor gets its own layer,

00:03:30.490 --> 00:03:31.940
and it's copy on open.

00:03:32.350 --> 00:03:33.990
A file you have open gets a copy

00:03:34.010 --> 00:03:35.620
with your unsaved text.

00:03:35.910 --> 00:03:38.220
Every other file comes from the disk layer.

00:03:38.850 --> 00:03:40.790
So I pass a number to greet again,

00:03:40.810 --> 00:03:41.880
and I don't save.

00:03:42.070 --> 00:03:43.510
My editor underlines the number,

00:03:43.530 --> 00:03:44.710
because the editor's layer

00:03:44.730 --> 00:03:46.440
has my unsaved text.

00:03:46.710 --> 00:03:47.870
The build is still ok,

00:03:47.890 --> 00:03:50.540
because the file on disk hasn't changed.

00:03:51.130 --> 00:03:52.440
We use the symbols from type checking

00:03:52.460 --> 00:03:53.180
to make decisions

00:03:53.200 --> 00:03:55.350
when we transform your files during emit.

00:03:55.620 --> 00:03:56.940
One example is the automatic

00:03:56.960 --> 00:03:58.510
async await transform.

00:03:58.900 --> 00:04:00.190
This is my function, listUsers.

00:04:00.840 --> 00:04:03.370
It calls sql, with no async and no await.

00:04:03.720 --> 00:04:05.620
This is the JavaScript the build wrote.

00:04:05.640 --> 00:04:07.950
It has async and await added automatically.

00:04:08.340 --> 00:04:08.920
During emit,

00:04:08.940 --> 00:04:10.740
the build looked up the symbol for sql,

00:04:10.760 --> 00:04:12.700
saw that sql has an async version,

00:04:12.720 --> 00:04:15.070
and added async and await automatically.

00:04:15.580 --> 00:04:16.500
That's a major benefit

00:04:16.520 --> 00:04:18.110
of sharing one source graph.

00:04:18.260 --> 00:04:19.400
The symbols from type checking

00:04:19.420 --> 00:04:21.630
are available during bundling and emit.

00:04:22.140 --> 00:04:23.880
Microsoft rewrote the TypeScript compiler

00:04:23.900 --> 00:04:26.150
in Go, and Elements is written in Go too.

00:04:26.400 --> 00:04:27.840
So we built TypeScript directly

00:04:27.860 --> 00:04:28.810
into Elements.

00:04:28.980 --> 00:04:30.060
We made a few changes.

00:04:30.080 --> 00:04:32.260
The type checker uses our own file watcher,

00:04:32.280 --> 00:04:33.420
multi-dimensional source graph,

00:04:33.440 --> 00:04:35.110
and change detection algorithms.

00:04:35.440 --> 00:04:36.740
It checks your code for the server

00:04:36.760 --> 00:04:38.430
and for the browser concurrently,

00:04:38.560 --> 00:04:40.300
and merges the errors into one list.

00:04:40.320 --> 00:04:42.000
And we added two new languages

00:04:42.020 --> 00:04:42.910
to TypeScript:

00:04:43.120 --> 00:04:45.110
reactive HTML and JSOC.

00:04:45.290 --> 00:04:47.170
A file in either language is a module,

00:04:47.190 --> 00:04:48.300
like a TypeScript file.

00:04:48.630 --> 00:04:50.030
A page can import a function

00:04:50.050 --> 00:04:51.020
from TypeScript.

00:04:51.450 --> 00:04:53.040
TypeScript can import your config.

00:04:53.330 --> 00:04:54.410
And one type checker checks

00:04:54.430 --> 00:04:55.810
all three languages together,

00:04:55.830 --> 00:04:57.140
across those imports.

00:04:57.360 --> 00:04:58.540
The build is triggered automatically

00:04:58.560 --> 00:04:59.830
when you save a file.

00:05:00.060 --> 00:05:00.640
When it's done,

00:05:00.660 --> 00:05:02.110
the errors are pushed to your editor,

00:05:02.220 --> 00:05:03.380
and they're available on request

00:05:03.400 --> 00:05:04.160
to other tools,

00:05:04.180 --> 00:05:05.710
like your terminal and your agents.

00:05:05.900 --> 00:05:06.550
So your agent

00:05:06.570 --> 00:05:08.130
doesn't run a type checker at all.

00:05:08.320 --> 00:05:09.270
It doesn't run tsc

00:05:09.290 --> 00:05:10.960
on every file in your project.

00:05:11.030 --> 00:05:11.930
It doesn't have to remember

00:05:11.950 --> 00:05:14.340
which files depend on the file it changed.

00:05:14.550 --> 00:05:15.830
The build has already type checked

00:05:15.850 --> 00:05:17.660
that file and its parent files.

00:05:17.930 --> 00:05:19.490
The agent reads any type errors,

00:05:19.510 --> 00:05:21.050
along with the rest of the build errors,

00:05:21.070 --> 00:05:22.480
with the elements build command.

00:05:22.670 --> 00:05:24.720
That command answers in microseconds.
