Skip to content

Commit e7f828f

Browse files
committed
docs: DTS
1 parent 5732401 commit e7f828f

File tree

1 file changed

+55
-0
lines changed
  • website/docs/en/guide/advanced

1 file changed

+55
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,56 @@
11
# DTS
2+
3+
This chapter introduces what TypeScript Declaration Files (DTS) are and how to generate DTS files in Rslib.
4+
5+
## What is DTS
6+
7+
TypeScript Declaration Files (DTS) provide type information for JavaScript code. DTS files typically have a `.d.ts` extension. They allow the TypeScript compiler to understand the type structure of JavaScript code, enabling features like:
8+
9+
1. **Type Checking**: Provide type information for JavaScript code, helping developers catch potential type errors at compile time.
10+
2. **Code Completion**: Enhance code editor features like autocomplete and code navigation.
11+
3. **Documentation Generation**: Generate documentation for JavaScript code, providing better developer experience.
12+
4. **IDE Support**: Improve the developer experience in IDEs like Visual Studio Code, WebStorm, and others.
13+
5. **Library Consumption**: Make it easier for other developers to use and understand your library.
14+
15+
## What are Bundle DTS and Bundleless DTS
16+
17+
### Bundle DTS
18+
19+
Bundle DTS involves bundling multiple TypeScript declaration files into a single declaration file.
20+
21+
- **Pros:**
22+
23+
- **Simplified Management**: Simplifies the management and referencing of type files.
24+
- **Easy Distribution**: Reduces the number of files users need to handle when using the library.
25+
26+
- **Cons:**
27+
- **Complex Generation**: Generating and maintaining a single bundle file can become complex in large projects.
28+
- **Debugging Challenges**: Debugging type issues may not be as intuitive as with separate files.
29+
30+
### Bundleless DTS
31+
32+
Bundleless DTS involves generating a separate declaration file for each module in the library, just like `tsc` does.
33+
34+
- **Pros:**
35+
36+
- **Modular**: Each module has its own type definitions, making maintenance and debugging easier.
37+
- **Flexibility**: Suitable for large projects, avoiding the complexity of a single file.
38+
39+
- **Cons:**
40+
- **Multiple Files**: Users may need to handle multiple declaration files when using the library.
41+
- **Complex Management**: May require additional configuration to correctly reference all files.
42+
43+
## How to Generate DTS in Rslib
44+
45+
Rslib defaults to generating bundleless DTS, which using [TypeScript Compiler API](https://github.com/microsoft/TypeScript/wiki/Using-the-Compiler-API) and bundle DTS is also supported by [API Extractor](https://api-extractor.com/).
46+
47+
If you want to generate bundleless DTS, you can:
48+
49+
- Set `dts: true` or `dts: { bundle: false }` in the Rslib configuration file.
50+
51+
If you want to generate bundle DTS, you can:
52+
53+
- Install `@microsoft/api-extractor` as a development dependency.
54+
- Set `dts: { bundle: true }` in the Rslib configuration file.
55+
56+
More details about DTS configuration, please refer to [lib.dts](/config/dts).

0 commit comments

Comments
 (0)