@@ -27,21 +27,14 @@ and manually modify.
2727Despite the magic of Path aliases, they are actually a standard ` package.json `
2828supported feature. Sort of.
2929[ The ` "imports" ` field] ( https://nodejs.org/api/packages.html#imports ) in
30- ` package.json ` allows you to configure aliases for your imports. It's not
31- exactly the same as TypeScript Path aliases, and using them doesn't give you
32- autocomplete with TypeScript
33- ([ yet] ( https://github.com/microsoft/TypeScript/pull/55015 ) ), but if you
34- configure both, then you can get the best of both worlds!
30+ ` package.json ` allows you to configure aliases for your imports.
31+ TypeScript also uses this for its own Path aliases since version 5.4
32+ so you get autocomplete and type checking for your imports.
3533
3634By using the ` "imports" ` field, you don't have to do any special configuration
3735for ` vitest ` or ` eslint ` to be able to resolve imports. They just resolve them
3836using the standard.
3937
40- And by using the ` tsconfig.json ` ` paths ` field configured in the same way as the
41- ` "imports" ` field, you get autocomplete and type checking for your imports. This
42- should hopefully be temporary until TypeScript supports the ` "imports" ` field
43- directly.
44-
4538One interesting requirement for ` imports ` is that they _ must_ start with the ` # `
4639character to disambiguate from other imports. This is a bit annoying, but it's
4740something that's not difficult to get used to. They also _ must not_ start with
@@ -50,19 +43,14 @@ again it's just a matter of familiarity. So it's no big deal.
5043
5144## Decision
5245
53- We're going to configure ` "imports" ` in the ` package.json ` and ` paths ` in the
54- ` tsconfig.json ` to use path aliases for imports.
46+ We're going to configure ` "imports" ` in the ` package.json ` to use path aliases for imports.
5547
5648We'll set it to ` "#*": "./*" ` which will allow us to import anything in the root
5749of the repo with ` #<dirname>/<filepath> ` .
5850
5951## Consequences
6052
6153This is unfortunately _ very_ soon after making the decision to drop the alias.
62- But I see this as slightly different because we're only using the alias to make
63- up for a shortcoming in TypeScript temporarily. Once TypeScript supports the
64- ` "imports" ` field, we can drop the ` paths ` field and just use the ` "imports" `
65- standard for Node.js.
6654
6755If someone wants to use the Epic Stack without Node.js, and their runtime
6856doesn't support ` package.json ` imports (I'm not sure whether other runtimes do
0 commit comments