Skip to content

Commit b8db8d6

Browse files
doc: add strip-types proposal
1 parent 50cb473 commit b8db8d6

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed

.DS_Store

6 KB
Binary file not shown.

doc/.DS_Store

6 KB
Binary file not shown.

doc/design/proposal-strip-types.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Strip Types Design
2+
3+
## Problem
4+
5+
TypeScript support has been for a few years at the top of the list of features that users want to see in Node.js.
6+
Discussion has been on going for a few years [#43818](https://github.com/nodejs/node/issues/43818), and the main blocker has been the lack of a clear on long term support.
7+
TypeScript does not follow semver, and the Node.js project has been reluctant to commit to supporting TypeScript in the long term, given that the lifespan of an LTS version is 3 years.
8+
9+
## Goals
10+
11+
- Make sure Node.js can support TypeScript with the stability guarantees that has always offered.
12+
- Avoid breaking the ecosystem by creating a new "flavor" that only works on Node.js.
13+
- Performance.
14+
- Keeping it simple, provide the foundations for user to build on top.
15+
16+
## Initial Proposal
17+
18+
The proposal is to add a new flag to the Node.js CLI, `--experimental-strip-types`, which will replace inline TypeScript types with whitespace.
19+
No type checking is performed, and types are discarded.
20+
21+
Example:
22+
23+
```typescript
24+
interface Foo {
25+
bar: string;
26+
}
27+
28+
throw new Error("Whitespacing");
29+
30+
```
31+
32+
Becomes:
33+
34+
```javascript
35+
36+
37+
38+
39+
throw new Error("Whitespacing");
40+
41+
```
42+
43+
> Note that the missing types are replaced with whitespace, so the line numbers are preserved, so that sourcemaps are not needed.
44+
45+
By removing types completely, we can avoid the need to commit to supporting TypeScript in the long term, as the feature is not a full TypeScript implementation.
46+
As in JavaScript files, file extensions are required in `import` statements and `import()` expressions.
47+
TypeScript features that depend on settings within `tsconfig.json`, such as paths or converting module formats, are unsupported.
48+
This will solve the long term compatibility issue, but might not be as complete as a full TypeScript implementation.
49+
50+
## Limitations
51+
52+
### `.js` extension for `.ts` files
53+
54+
The reason is that the compiler/bundler should be responsible to resolve the correct extension at compile time.
55+
At runtime, the extension must be correct, not to add overhead in production when it can be solved during development.
56+
This is an issue that should apply to all tools that execute TypeScript at runtime.
57+
58+
### No type checking
59+
60+
Type checking should be done by user land tools during development, and not at runtime.
61+
By performing at runtime, we would be adding large overhead.
62+
63+
### Running TypeScript in node_modules
64+
65+
The proposal does not support running TypeScript files in `node_modules`.
66+
This is to avoid encouraging package maintainers to ship TypeScript files in their packages. This has been explicitly requested by TypeScript maintainers.
67+
68+
### Monorepos support
69+
70+
Due to not running TypeScript in `node_modules`, monorepos are not supported.
71+
This is a limitation that should be solved by user land tools.

0 commit comments

Comments
 (0)