Skip to content

Commit f1f4782

Browse files
committed
📝 more on --out
1 parent 9d9d03b commit f1f4782

File tree

1 file changed

+51
-5
lines changed

1 file changed

+51
-5
lines changed

docs/out.md

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff 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
77
* Hard to analyze
88
* Hard to scale
99
* `_references`
10+
* Code reuse
11+
* Multiple Targets
1012

1113
## Runtime Errors
1214

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.
1416

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+
class Foo {
22+
23+
}
24+
```
25+
26+
and a `bar.ts`:
27+
```ts
28+
class Bar extends Foo {
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+
module App {
40+
export var foo = 123;
41+
}
42+
```
43+
And `bar.ts`:
44+
```ts
45+
module App {
46+
export var 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`.
1751

1852
## Fast compile
1953
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.
2054

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+
2157
## Global Scope
2258
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.
2359

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+
2462
## 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.
2666

2767
## 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.
2969

3070
## `_references.ts`
3171
Isn't supported by `tsconfig.json` : https://github.com/Microsoft/TypeScript/issues/2472#issuecomment-85330803 You'll have to manually sort the `files` array.
3272

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+
3379
## Summary
3480
`--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

Comments
 (0)