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

Proposal: emit files without .ts extension to get custom file extension #30076

Closed
5 tasks done
magic-akari opened this issue Feb 25, 2019 · 3 comments
Closed
5 tasks done
Labels
Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript

Comments

@magic-akari
Copy link
Contributor

Search Terms

  • file extension
  • .mjs
  • .esm

Suggestion

It is very useful if you can customize the output extension.
But mapping extension is boring and painful.
Maybe there is another way to make this easier.
If we don't map the extension, we just erase the .ts or .tsx extension to achieve it.
A compilerOptions is needed to prevent break existing TypeScript code.

Use Cases

  • Output the .mjs file for Node Module,
  • Output .es or other file extensions without additional steps. (e.g. useful for tsc watching mode)

Examples

input:

// src/lib.js.ts
export const result = 42;
// src/index.js.ts
import { result } from "./lib.js";

console.log(result);

output:

// build/lib.js
export const result = 42;
// build/index.js
import { result } from "./lib.js";

console.log(result);

input:

// src/lib.mjs.ts
export const result = 42;
// src/index.mjs.ts
import { result } from "./lib.mjs";

console.log(result);

output:

// build/lib.mjs
export const result = 42;
// build/index.mjs
import { result } from "./lib.mjs";

console.log(result);

input:

// src/lib.myext.ts
export const result = 42;
// src/index.myext.ts
import { result } from "./lib.myext";

console.log(result);

output:

// build/lib.myext
export const result = 42;
// build/index.myext
import { result } from "./lib.myext";

console.log(result);

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, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.
@RyanCavanaugh RyanCavanaugh added Suggestion An idea for TypeScript Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature labels Feb 27, 2019
@magic-akari
Copy link
Contributor Author

magic-akari commented Apr 17, 2019

@xialvjun
Copy link

just add a compiler option --outSuffix so tsc --module es6 --outSuffix mjs...
#32373

@viT-1
Copy link

viT-1 commented Aug 15, 2019

Problem is wider, I need in --outSuffix /index.js =)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants