Skip to content

New modules docs #2946

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions packages/documentation/copy/en/modules-reference/Introduction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
title: Modules - Introduction
short: Introduction
layout: docs
permalink: /docs/handbook/modules/introduction.html
oneline: How TypeScript models JavaScript modules
translatable: true
---

This document is divided into four sections:

1. The first section develops the [**theory**](/docs/handbook/modules/theory.html) behind how TypeScript approaches modules. If you want to be able to write the correct module-related compiler options for any situation, reason about how to integrate TypeScript with other tools, or understand how TypeScript processes dependency packages, this is the place to start. While there are guides and reference pages on these topics, building an understanding of these fundamentals will make reading the guides easier, and give you a mental framework for dealing with real-world problems not specifically covered here.
2. The [**guides**](/docs/handbook/modules/guides/choosing-compiler-options.html) show how to accomplish specific real-world tasks, starting with picking the right compilation settings for a new project. The guides are a good place to start both for beginners who want to get up and running as quickly as possible and for experts who already have a good grasp of the theory but want concrete guidance on a complicated task.
3. The [**reference**](/docs/handbook/modules/reference.html) section provides a more detailed look at the syntaxes and configurations presented in previous sections.
4. The [**appendices**](/docs/handbook/modules/appendices/esm-cjs-interop.html) cover complicated topics that deserve additional explanation in more detail than the theory or reference sections allow.
1,147 changes: 1,147 additions & 0 deletions packages/documentation/copy/en/modules-reference/Reference.md

Large diffs are not rendered by default.

367 changes: 367 additions & 0 deletions packages/documentation/copy/en/modules-reference/Theory.md

Large diffs are not rendered by default.

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions packages/documentation/copy/en/modules-reference/diagrams/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Some of this content uses mermaid diagrams. We could render them as part of the website build with gatsby-remark-mermaid, but that requires puppeteer/Chromium, which has historically caused a lot of cross-platform build issues. These diagrams should not change often, so I’m just going to store the source here and generate the SVGs manually.

Example:

```sh
npm install -g @mermaid-js/mermaid-cli
mmdc -i packages/documentation/copy/en/modules-reference/diagrams/esm-cjs-interop.md
```

declaration-files.svg is a non-Mermaid replacement for theory.md-4.svg. I made it for a talk one time and it’s better than what Mermaid can do with a flowchart.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
```mermaid
graph TB
subgraph Transpiled[ESM transpiled to CJS]
direction TB
C[Importing module] -- designed based on spec --> D[Imported module]
end
subgraph ESM
direction TB
A[Importing module] -- specified behavior --> B[Imported module]
end
```

```mermaid
graph TD
subgraph Transpiled[ESM transpiled to CJS]
C[Importing module] -- designed based on spec --> D[Imported module]
end
subgraph CJS[True CJS]
E[Imported module]
end
subgraph ESM
A[Importing module] -- specified behavior --> B[Imported module]
end
A -. unspecified behavior .-> E
C .->|"<span style='font-size: 3em'>❓🤷🏻‍♂️❓</span>"| E
```
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading