Skip to content

Commit b3a1b72

Browse files
Mention experimental specifier resolution in TypeScript recipe
Co-authored-by: Mark Wubben <[email protected]>
1 parent 77623a5 commit b3a1b72

File tree

1 file changed

+2
-14
lines changed

1 file changed

+2
-14
lines changed

docs/recipes/typescript.md

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,9 @@ You also need to have this in your `tsconfig.json`:
5656
}
5757
```
5858

59-
And finally, even though you directly import code from your TypeScript files, you **must** import it from your `.ts` files with the `.js` extension instead!
59+
Remember that, by default, ES modules require you to specify the file extension and TypeScript outputs `.js` files, so you have to write your imports to load from `.js` files not `.ts`.
6060

61-
For example if your source file is `index.ts` looks like this:
62-
63-
```ts
64-
export function myFunction() {}
65-
```
66-
67-
Then in your AVA test files you must import it **as if it has the `.js` extension** it like so:
68-
69-
```ts
70-
import {myFunction} from './index.js';
71-
```
72-
73-
The reason that you need to write `.js` to import `.ts` files in your AVA test files, is explained by the `ts-node` author [in this post](https://github.com/nodejs/modules/issues/351#issuecomment-621257543).
61+
If this is not to your liking there is an _experimental_ option in Node.js that you might want to use. You can add it to the `nodeArguments` array in the AVA configuration so it applies to your test runs: [`--experimental-specifier-resolution=node`](https://nodejs.org/api/esm.html#customizing-esm-specifier-resolution-algorithm).
7462

7563
#### For packages without type "module"
7664

0 commit comments

Comments
 (0)