lukeed / tsm

TypeScript Module Loader
MIT License
1.18k stars 19 forks source link

feat: Allow JavaScript extensions for TypeScript imports #2

Closed lukeed closed 2 years ago

lukeed commented 2 years ago

Closes #1

When inside any TypeScript file (.ts, .tsx, .cts, or .mts) you may now write import statements to other TypeScript files, but using their would-be JavaScript extensions.

For example, assume this file structure:

demo
├── aaa.ts
├── bbb.cts
├── ccc.mts
└── main.ts

And now the main.ts file includes the following:

import aaa from './aaa.js';
// => loads the "aaa.ts" file

import bbb from './bbb.cjs';
// => loads the "bbb.cts" file

import ccc from './ccc.mjs';
// => loads the "ccc.mts" file

This is/will be supported officially by TypeScript. See here for more info