# Modules

TypeScript is made to adapt to JavaScript. And JavaScript itself has had many module systems for different environments and times. Most notably:

* The browser console "vanilla" environment is module-less. Every imported file lives in the global scope;
* node.js traditionally uses the "commonjs" module syntax;
* Modern front-end code built with module bundlers usually use the "es-modules" syntax;

## Module-less typescript

* A TypeScript file is considered module-less if it has no imports or exports;
* All typescript source files share the same global context. Which is defined at the `include` entry of the tsconfig;
* A file can manually include a reference through the addition of the "triple slash directive" at the first line.

```
///<reference path=“./path/to/file”/>
```

## Moduleful typescript

* The TS import syntax comes from the es-module syntax;
* You can also write some additional syntax not covered by the es-modules:

```typescript
import express = require("express") // enforce commonjs import
const express = require("express")  // this works BUT 3rd party types won't get imported
import * as express from 'express'
import express from 'express' // only works with "esModuleInterop"
export = { something: 'x' } // "module.exports =" syntax from commonjs
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://wkrueger.gitbook.io/typescript/modules.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
