Feature Request: allow change file extension of generated files from `.ts`
See original GitHub issueSuggestion
🔍 Search Terms
List of keywords you searched for before creating this issue. Write them down here so that others can find this suggestion more easily and help provide feedback.
✅ 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 something like
{
"compilerOptions": {
"module": "nodenext",
"targetExtension": ".cjs",
}
📃 Motivating Example
- when
targetExtension
is.cjs
, all.ts
will emit as.cjs
, but.mts
still is emit as.mjs
- when
targetExtension
is.mjs
, all.ts
will emit as.mjs
, but.cts
still is emit as.cjs
💻 Use Cases
Issue Analytics
- State:
- Created a year ago
- Reactions:6
- Comments:15 (6 by maintainers)
Top Results From Across the Web
TSConfig Reference - Docs on every TSConfig option
If a glob pattern doesn't include a file extension, then only files with supported ... and .d.ts by default, with .js and .jsx...
Read more >User and Workspace Settings - Visual Studio Code
This feature lets you share settings, keyboard shortcuts, and installed extensions across your VS Code installs on various machines. You can enable Settings ......
Read more >TypeScript support in Svelte - Learn web development
You can rename most of your .js files to .ts files and they will just ... Type information allows code editors and IDEs...
Read more >ts-loader - npm
By default, ts-loader will not compile .ts files in node_modules . You should not need to recompile .ts files there, but if you...
Read more >File types supported by Windows Media Player
dvr-ms file format for storing recorded TV content. Similar to *.asf files, *.dvr-ms file enhancements permit key Personal Video Recorder (PVR) functionality, ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’ve met same issue when I building dual package.
e.g. https://github.com/azu/check-ends-with-period/tree/v2.0.0 (It is invalid example as dual package) TypeScript source code is in
src/*.ts
andpackage.json
has"type": "module"
field. Also, this repository has two tsconfig files.tsconfig.json
: generates esm tomodule/*.js
fromsrc/*.ts
tsconfig.cjs.json
: generates cjs tolib/*.js
fromsrc/*.ts
I’ve defined
exports
field as follows, but this package was treated as ESM because"type": "module"
is defined. As a result, This package can not be requred from CJS without dynamic import. (Node.js treats*.js
file as ESM by"type": "module"
)I could not found just works solution without using bundler/post scripts.
If
targetExtension
option exists, I can resolve this issue by tsconfig file.tsconfig.json
+"targetExtension": ".mjs"
,: generates esm tomodule/*.mjs
fromsrc/*.ts
tsconfig.cjs.json
+"targetExtension": ".cjs"
,: generates cjs tolib/*.cjs
fromsrc/*.ts
However, this option will need to rewrite import path of source code. It oppsite TypeScript’s design goal.
Major use-case is building dual-package with
tsc
without any postbuild script, I think.