Will typescript-go support importing .ts extensions? #1670
Replies: 2 comments 2 replies
-
|
TS7 will have the same module primitives (minus deprecated ones) as TS 5.9/6.0 What you're describing is already broadly possible with |
Beta Was this translation helpful? Give feedback.
-
|
TypeScript’s stance is that it focuses on type-checking, not replacing bundlers or loaders. In fact, modern TypeScript already provides an option to allow direct .ts imports: the --allowImportingTsExtensions compiler flag lets you import files with their .ts extension in code . Additionally, TypeScript 5.7 introduced --rewriteRelativeImportExtensions to automatically turn relative .ts imports into .js in the emitted output . This means if you run TypeScript without a bundler (e.g. in Node’s native ES modules or Deno), you can use .ts in import statements and have the compiler output correct .js paths  . However, full “bundler-like” path resolution is not planned. For example, TypeScript will not rewrite imports for your custom path aliases or bare module imports – those still require a bundler or loader. The core team has stated that supplanting bundlers is out of scope for TypeScript . TypeScript 7 (as used in the Go compiler) will have the same module resolution features as recent versions : use allowImportingTsExtensions for direct .ts imports, but don’t expect TypeScript to handle things like alias path mapping or tree-shaking. In short, yes – you can import .ts files directly using the existing compiler options, but no – TypeScript/TS-Go won’t intrinsically handle all bundler tasks like alias rewriting or combining modules. The TypeScript team’s philosophy is that bundlers and build tools already do an excellent job at those tasks, and TypeScript should “focus on one important thing” – providing type safety . So you’ll likely continue to use bundlers (or Node’s loader hooks) for advanced resolution, while TypeScript ensures your types are checked and outputs JavaScript as needed. For reference, the TypeScript lead has noted that features like path alias rewriting are unlikely to be added – the recommended approach is to use bundler plugins or the above compiler flags for .ts import support  . This approach keeps TypeScript simple and lets bundlers (Webpack, Vite, etc.) handle optimization and module resolution beyond .ts extension handling. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Will TypeScript 7 support modern path-resolution like Vite, esbuild, etc?
There's a tc39 proposal for browsers to support type stripping, so that TypeScript files could be imported and run directly in the browser.
It raises the question of what a TypeScript source file "should" look like. TypeScript is an idealized form of JavaScript, with the role of tsc being to transform the idealized form into the compatible form.
The world has overwhelmingly chosen
.tsimports. It would be a huge win if typescript 7 could eclipse bundlers.EDIT: I forgot to mention, I know that TypeScript 5.7 introduced the
rewriteRelativeImportExtensionsoption, but it is an incomplete imlementation that doesn't support path aliases like@/utils/example.tsBeta Was this translation helpful? Give feedback.
All reactions