Skip to content

docs: clarify export {} comment in global-modifying-module templates Improvements: #3410 (Issue) #3414

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

Open
wants to merge 1 commit into
base: v2
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,19 @@ export interface StringFormatOptions {
/*~ For example, declaring a method on the module (in addition to its global side effects) */
export function doSomething(): void;

/*~ If your module exports nothing, you'll need this line. Otherwise, delete it */
/*~
If your module does not export anything, include this line to explicitly mark the file as a module.

By default, TypeScript treats files without any import or export statements as scripts,
meaning their declarations are considered global. This can cause conflicts, such as
duplicate identifier errors, especially when you are augmenting or extending global types.

Adding `export {}` tells TypeScript that this file is a module. This scopes the declarations
to the module, preventing them from leaking into the global scope and avoiding naming conflicts.

For more information on how TypeScript distinguishes between scripts and modules, see:
https://www.typescriptlang.org/docs/handbook/modules.html#code-organization
*/
export {};

```