Skip to content

Add a config to control no import or export define file types only work in local, not pollute global types. #45353

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

Closed
4 tasks done
zenHeart opened this issue Aug 7, 2021 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@zenHeart
Copy link

zenHeart commented Aug 7, 2021

Suggestion

πŸ” Search Terms

scoped module config

βœ… Viability Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • [X ] This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

⭐ Suggestion

Add a config to control file type work in global scope or module scope.

πŸ“ƒ Motivating Example

In official docs module

a file without any top-level import or export declarations is treated as a script whose contents are available in the global scope (and therefore to modules as well).

This means not use export or import in the file, the file's type will work globally. Sometimes we need no import or export file types just work in the current file don't pollute the environment globally. For example:

  1. the tests file, we just declare some local test functions, it didn't rely any dependency, doesn't have any export or import define, but this make types in this file will pollute global. so I need to use like export {} to hack this.
  2. When writing some docs, I need to create many example files, these example file types just work locally, some example file doesn't have any export or import define, this also pollute globally. To avoid this situation I need to use some like type Fooxx to avoid name collesion or use like export {} to hack this.

I want there is some way to control which file or directory type will be not working globally. some config like

{
 // file has no import or export define, type only work in local
 "moduleScopeFiles" : [ "a.ts", "test/foo*.ts" ]
}

I found there is some config that can control umd export work in global allowUmdGlobalAccess, So I think this feature will also can control by config.

πŸ’» Use Cases

see previous example

@RyanCavanaugh
Copy link
Member

Tracked at #18232

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Aug 9, 2021
@typescript-bot
Copy link
Collaborator

This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants