Skip to content

Option that treat each js file as module #42748

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
5 tasks done
redradist opened this issue Feb 10, 2021 · 2 comments
Closed
5 tasks done

Option that treat each js file as module #42748

redradist opened this issue Feb 10, 2021 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@redradist
Copy link

redradist commented Feb 10, 2021

Suggestion

Add option "typeJs": "module" (default could be "typeJs": "script")

πŸ” Search Terms

How to say TypeScript that each js file is a module ?
How treat in TypeScript each js file as module ?

βœ… 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

Add option "typeJs": "module" (default could be "typeJs": "script")

πŸ“ƒ Motivating Example

In NodeJs we have ability to say which module system we use by setting "type": "module" in package.json
But when I add allowJs option TypeScript compiler treat each js file as plain script and it complains about redeclaration of the same function.
It would be nice instead of renaming each js -> mjs or adding stub export {}; statement to treat each js file as module, to add option, the same way node did

πŸ’» Use Cases

It is needed in case for example where in project bunch of scratches js files with some code that do not import or export something at this moment

@redradist redradist changed the title Option that understand each js file as module Option that treat each js file as module Feb 10, 2021
@RyanCavanaugh
Copy link
Member

See #14279

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Feb 12, 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