-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
New --emitExtension and --noImplicitExtensionName compiler options #35148
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, |
I want to use TypeScript to check the types. But to compile the code fast I want to strip the types with When I write in some of my files When I write instead This code, a.js: import b from './b.ts'
console.log(b) b.ts: export default 'blub' is valid JavaScript, it just does not work in Node.JS, as the latter refuses to accept .ts file extension. But when b.ts is delivered with the correct mime type, then this works: <html>
<body><script type='module' src='./a.js'></script>
Firefox and Epiphany print “blub” on the console.</body>
</html> Demonstration: https://mail.aegee.org/dpa/35148/file.html To sum up, import b from './b.ts' is valid JavaScript, and tsc refuses to accept valid JavaScript. How to get now the same input working in both tsc 3.9.2 and |
- 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
deno
andbrowser
style import. Note: This pr doesn't include URI style import resolution (https://deno.land/...
orstd:kv-storage
...), about URI style import, see #35749New
--noImplicitExtensionName
compiler 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
--emitExtension
compiler options.This flag allows tsc to emit
.mjs
,.es.js
,.es
,.ts
or any extension user specifies.tsconfig.json
Source files:
Emitted files:
Discussions
According to #35163 (comment) maybe
--noImplicitExtensionName
should be default totrue
when 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.
--emitExtension
emitExtension
.ts
and.tsx
file whenemitExtension
===.ts
or.tsx
Resolve TS file by
--emitExtension
Resolve type of
import './x.mjs'
to the filex.ts
.Will NOT rewrite the emitted file path.