-
Notifications
You must be signed in to change notification settings - Fork 12.8k
rewriteRelativeImportExtensions & enforce consistent extensions #61021
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
Comments
It seems like the only way you get in trouble with this is if you do "side-by-side" (e.g. no |
That's not exactly what I want to described (who can live with side-by-side compilation?!), but you're perfectly right when saying it will fail at runtime, there's no question about that. I try to described a check before the runtime. The idea behind this is when you activate It's a kind of code base |
A new option |
Tying this behavior to |
@aaronadamsCA it seems that you only need to run TS code in place and forget that it's not the only usage of TS. The suggestion here tries to cover wider usages, in particular, how to write and setup a single TS code base built via tsc to be distributed in form of |
π Search Terms
"rewriteRelativeImportExtensions", "extensions"
β Viability Checklist
β Suggestion
An option/param to enforce
import
s with relative paths to point to files existing in sources rather than in built files, in short, makeimport
s only allowing.ts
and not.js
extensions when importing a Typescript file.π Motivating Example
rewriteRelativeImportExtensions
is a great new feature and it works well. It permits to create hybrid projects directly executed by recent nodejs versions, but also buildable by tsc for distributing them. But since we now have the possibility to use the.ts
extensions inimport
s because they will be rewritten at compilation time, we still can continue to use the.js
extensions in parallel, pointing to built files.As everyone knows, nodejs requires relative
import
s to have an extension and to point to an existing file and so, extensions have to be.ts
(or.mts
/.cts
) to import other Typescript files.It would be probably great that Typescript gives us an error when using unreachable file in this context, like its quasi-exact opposite:
TS5097: An import path can only end with a .ts extension when allowImportingTsExtensions is enabled
when.ts
extensions are not allowed by configs.π» Use Cases
What do you want to use this for?
In projects where nodejs can be used for any reason (tests, various scripts) and where code have to be built to be distributed over npm or any other repository, to avoid detecting bad
import
s extensions at nodejs runtime and to keep a consistent code base.What shortcomings exist with current approaches?
Only its permittivity, allowing to use inconsistent
import
s styles, that may don't run in nodejs, without detecting them at coding time.What workarounds are you using in the meantime?
It's not a bug, there's no need of workarounds, only vigilance.
The text was updated successfully, but these errors were encountered: