-
Notifications
You must be signed in to change notification settings - Fork 13.1k
New --emitExtension and --noImplicitExtensionName compiler options #35148
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
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
0ddfa56 to
cba7725
Compare
cba7725 to
5b9ffb0
Compare
|
@DanielRosenwasser @RyanCavanaugh Hello, I have fully rewrittened this PR. Please checkout the new behavior! (There is no path rewriting anymore!) |
|
The thing that bugs me about including extensions as enforced by the |
|
I'm sorry but the ts team doesn't accept the previous version of this pr that will do the extension name rewrite for you. So I think there is no way to resolve this problem. @MicahZoltu |
|
Yeah, I have been following along and am frustrated with the current situation. Browser and NodeJS have diverged, and TypeScript is caught in the middle with an unwillingness to resolve that divergence on behalf of users. This means TypeScript users are forced to "pick a side" and they can no longer write TypeScript that runs in both browser and NodeJS. My plan for the time being is to continue using a TypeScript transformer to add the extension as part of the TSC build process. This way I can use a different transformer based on target without having to write TypeScript that has "picked a side". |
|
I guess https://github.com/cevek/ttypescript is a good project to start with for your case |
|
About deno & browser style import, see: #35749 |
|
if ts team ( @sandersn ) wants me to rebase my code to the latest codebase, @ me at any time! |
|
+1 |
|
@rbuckton I added you as the main reviewer since #33306 was assigned to you for 3.8.1, |
4c5c985 to
bf4e8ff
Compare
|
@weswigham @rbuckton |
- TypeScript fails to correctly generate an ESM module with correct line endings - ref: <microsoft/TypeScript#18442 (comment)> - ref: <microsoft/TypeScript#18442> - ref: <microsoft/TypeScript#37582> - ref: <microsoft/TypeScript#35148>
- TypeScript fails to correctly generate an ESM module with correct line endings - ref: <microsoft/TypeScript#18442 (comment)> - ref: <microsoft/TypeScript#18442> - ref: <microsoft/TypeScript#37582> - ref: <microsoft/TypeScript#35148>
- TypeScript fails to correctly generate an ESM module with correct line endings - ref: <microsoft/TypeScript#18442 (comment)> - ref: <microsoft/TypeScript#18442> - ref: <microsoft/TypeScript#37582> - ref: <microsoft/TypeScript#35148>
- TypeScript fails to correctly generate an ESM module with correct line endings - ref: <microsoft/TypeScript#18442 (comment)> - ref: <microsoft/TypeScript#18442> - ref: <microsoft/TypeScript#37582> - ref: <microsoft/TypeScript#35148>
- TypeScript fails to correctly generate an ESM module with correct line endings - ref: <microsoft/TypeScript#18442 (comment)> - ref: <microsoft/TypeScript#18442> - ref: <microsoft/TypeScript#37582> - ref: <microsoft/TypeScript#35148>
- TypeScript fails to correctly generate an ESM module with correct line endings - ref: <microsoft/TypeScript#18442 (comment)> - ref: <microsoft/TypeScript#18442> - ref: <microsoft/TypeScript#37582> - ref: <microsoft/TypeScript#35148>
- TypeScript fails to correctly generate an ESM module with correct line endings - ref: <microsoft/TypeScript#18442 (comment)> - ref: <microsoft/TypeScript#18442> - ref: <microsoft/TypeScript#37582> - ref: <microsoft/TypeScript#35148>
- TypeScript fails to correctly generate an ESM module with correct line endings - ref: <microsoft/TypeScript#18442 (comment)> - ref: <microsoft/TypeScript#18442> - ref: <microsoft/TypeScript#37582> - ref: <microsoft/TypeScript#35148>
- TypeScript fails to correctly generate an ESM module with correct line endings - ref: <microsoft/TypeScript#18442 (comment)> - ref: <microsoft/TypeScript#18442> - ref: <microsoft/TypeScript#37582> - ref: <microsoft/TypeScript#35148>
- TypeScript fails to correctly generate an ESM module with correct line endings - ref: <microsoft/TypeScript#18442 (comment)> - ref: <microsoft/TypeScript#18442> - ref: <microsoft/TypeScript#37582> - ref: <microsoft/TypeScript#35148>
- TypeScript fails to correctly generate an ESM module with correct line endings - ref: <microsoft/TypeScript#18442 (comment)> - ref: <microsoft/TypeScript#18442> - ref: <microsoft/TypeScript#37582> - ref: <microsoft/TypeScript#35148>
- TypeScript fails to correctly generate an ESM module with correct line endings - ref: <microsoft/TypeScript#18442 (comment)> - ref: <microsoft/TypeScript#18442> - ref: <microsoft/TypeScript#37582> - ref: <microsoft/TypeScript#35148>
- TypeScript fails to correctly generate an ESM module with correct line endings - ref: <microsoft/TypeScript#18442 (comment)> - ref: <microsoft/TypeScript#18442> - ref: <microsoft/TypeScript#37582> - ref: <microsoft/TypeScript#35148>
- TypeScript fails to correctly generate an ESM module with correct line endings - ref: <microsoft/TypeScript#18442 (comment)> - ref: <microsoft/TypeScript#18442> - ref: <microsoft/TypeScript#37582> - ref: <microsoft/TypeScript#35148>
|
What's the status? |
|
Typescript team rejected this idea 😭 |
…tensions) - TypeScript fails to correctly generate an ESM module with correct file extensions - ref: <microsoft/TypeScript#18442 (comment)> - ref: <microsoft/TypeScript#18442> - ref: <microsoft/TypeScript#37582> - ref: <microsoft/TypeScript#35148>
This comment has been minimized.
This comment has been minimized.
|
@Jack-Works Why? |
|
There are some options for dealing with this that might suit some use cases described here:
|
Related: denoland/deno#8529, #27957, #35749
fixes #30076, fixes #18442, fixes #16577, fixes #33306
See also: Node.js new ESModule support: https://medium.com/@nodejs/announcing-core-node-js-support-for-ecmascript-modules-c5d6dc29b663
Summary
Improve support for
denoandbrowserstyle import. Note: This pr doesn't include URI style import resolution (https://deno.land/...orstd:kv-storage...), about URI style import, see #35749New
--noImplicitExtensionNamecompiler options.With this option on, the following code becomes invalid.


This new options will enforce developer to write valid import path on
deno(noImplicitExtensionName + emitExtension=.ts) and ES Module for browser (noImplicitExtensionName + emitExtension=.js (default value)).New
--emitExtensioncompiler options.This flag allows tsc to emit
.mjs,.es.js,.es,.tsor any extension user specifies.tsconfig.json
{ compilerOptions: { emitExtension: ".mjs", noImplicitExtensionName: true } }Source files:

Emitted files:

Discussions
According to #35163 (comment) maybe
--noImplicitExtensionNameshould be default totruewhen the target module system is ESModuleDetails
Due to the ts meeting note for this pr (#35589 )
I decided to rewrite ts pr to follow the ts design principle.
--emitExtensionemitExtension.tsand.tsxfile whenemitExtension===.tsor.tsxResolve TS file by
--emitExtensionResolve type of
import './x.mjs'to the filex.ts.Will NOT rewrite the emitted file path.