You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/out.md
+51-5Lines changed: 51 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -7,28 +7,74 @@ We do not support `--out` as we think its a bad idea for you to use because of t
7
7
* Hard to analyze
8
8
* Hard to scale
9
9
*`_references`
10
+
* Code reuse
11
+
* Multiple Targets
10
12
11
13
## Runtime Errors
12
14
13
-
If your code depends on any form of js ordering you will get random errors and runtime.
15
+
If your code depends on any form of js ordering you will get random errors at runtime.
14
16
15
-
* class inheritance can break at runtime.
16
-
* module splitting can fail at runtime.
17
+
***class inheritance can break at runtime.**
18
+
19
+
Consider `foo.ts`:
20
+
```ts
21
+
classFoo {
22
+
23
+
}
24
+
```
25
+
26
+
and a `bar.ts`:
27
+
```ts
28
+
classBarextendsFoo {
29
+
30
+
}
31
+
```
32
+
33
+
If you fail to compile it in correct order e.g. perhaps alphabetically `tsc bar.ts foo.ts` the code will compile fine but error at runtime with `ReferenceError`.
34
+
35
+
***module splitting can fail at runtime.**
36
+
37
+
Consider `foo.ts`:
38
+
```ts
39
+
moduleApp {
40
+
exportvar foo =123;
41
+
}
42
+
```
43
+
And `bar.ts`:
44
+
```ts
45
+
moduleApp {
46
+
exportvar bar =foo+456;
47
+
}
48
+
```
49
+
50
+
If you fail to compile it in correct order e.g. perhaps alphabetically `tsc bar.ts foo.ts` the code will compile fine but *silently* fail at runtime with `bar` set to `NaN`.
17
51
18
52
## Fast compile
19
53
If you use `--out` then single `.ts` files cannot be codegened into single `.js` files in isolation without unnecessary hacks. `--out` essentially forces a slower incremental build.
20
54
55
+
Also source maps are positionally sensitive and run-length encoded so most of the map has to be rebuilt on a recompile if you use source maps (which you should!). At high-10s to 100s kloc combined it’s going to get slow.
56
+
21
57
## Global Scope
22
58
Sure you can use name spaces but its still on `window` if you run it in the browser. Namespaces are just an unnecessary workaround. Also `/// <reference` comments introduce an global context in *your code* that can get hard to maintain.
23
59
60
+
Also if your company has several teams working independently and then someone decides to try integrating two independently written apps there is a high likelihood of a name conflict.
61
+
24
62
## Hard to analyze
25
-
We wish to provide more code analysis tools. These will be easier if you provide us with the dependency chain (implicitly there on a silver platter using external modules).
63
+
We wish to provide more code analysis tools. These will be easier if you provide us with the dependency chain (implicitly there on a silver platter using external modules).
64
+
65
+
Also its not just the *dev tools* that have a hard time making sense of the code. The next human needs to understand a lot of the code base before they start to understand where stuff is actually imported from. Using internal modules also makes code difficult to review in isolation e.g. on github.
26
66
27
67
## Hard to scale
28
-
Really just a result of random runtime errors + slower and slower compile times.
68
+
Really just a result of random runtime errors + slower and slower compile times + difficulty in understanding someone else's code.
29
69
30
70
## `_references.ts`
31
71
Isn't supported by `tsconfig.json` : https://github.com/Microsoft/TypeScript/issues/2472#issuecomment-85330803 You'll have to manually sort the `files` array.
32
72
73
+
## Code reuse
74
+
If you want to reuse a portion of your code in another project, with all that *implicit* dependency management, it will be difficult to port it over without potential runtime errors.
75
+
76
+
## Multiple Targets
77
+
Also if you decide to reuse your browser code in something like nodejs (e.g. for *testing* APIs) you are going to need to port it over to a module system or come up with ugly hacks to make the nodejs `global` your new global scope (i.e. `window`).
78
+
33
79
## Summary
34
80
`--out` is really the job of some build tool. And even such a build tool can benefit from the dependency mentions provided by external modules. So we recommend you use external modules and then let the build tool create a single `.js` for you if you so desire.
0 commit comments