Skip to content
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

Remove warnings on empty file when enabled IsolatedModules #47800

Closed
5 tasks done
hyrious opened this issue Feb 8, 2022 · 1 comment
Closed
5 tasks done

Remove warnings on empty file when enabled IsolatedModules #47800

hyrious opened this issue Feb 8, 2022 · 1 comment
Labels
Duplicate An existing issue was already created

Comments

@hyrious
Copy link

hyrious commented Feb 8, 2022

Suggestion

TypeScript has a simple guess on whether the input file is in es modules or global script by seeing it includes keywords like import, export. So an empty file becomes non-esm and triggers an error ts(1208): 'file.ts' cannot be compiled under '--isolatedModules' because it is considered a global script file. Add an import, export, or an empty 'export {}' statement to make it a module..

However, as you may know empty files are also valid es modules. I think it is safe to remove this error/warning and just treat an empty file as in esm.

Rollup and esbuild also treat empty files as ESM too.

🔍 Search Terms

IsolatedModules, empty, esm, warning.

✅ Viability Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • 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

Treat empty files as es modules when "IsolatedModules" is on.

📃 Motivating Example

💻 Use Cases

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Feb 8, 2022
@RyanCavanaugh
Copy link
Member

See #47495

@hyrious hyrious closed this as completed Feb 9, 2022
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

2 participants