22
33Date: 2023-08-16
44
5- Status: accepted
5+ Status: superseded by [ 046-remove-path-aliases] ( ./046-remove-path-aliases.md ) 
6+ due to TypeScript's native support for the ` "imports" `  field in package.json.
67
78## Context  
89
@@ -27,21 +28,14 @@ and manually modify.
2728Despite the magic of Path aliases, they are actually a standard ` package.json ` 
2829supported feature. Sort of.
2930[ 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!
31+ ` package.json `  allows you to configure aliases for your imports.
32+ TypeScript also uses this for its own Path aliases since version 5.4
33+ so you get autocomplete and type checking for your imports.
3534
3635By using the ` "imports" `  field, you don't have to do any special configuration
3736for ` vitest `  or ` eslint `  to be able to resolve imports. They just resolve them
3837using the standard.
3938
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- 
4539One interesting requirement for ` imports `  is that they _ must_  start with the ` # ` 
4640character to disambiguate from other imports. This is a bit annoying, but it's
4741something that's not difficult to get used to. They also _ must not_  start with
@@ -50,19 +44,14 @@ again it's just a matter of familiarity. So it's no big deal.
5044
5145## Decision  
5246
53- We're going to configure ` "imports" `  in the ` package.json `  and ` paths `  in the
54- ` tsconfig.json `  to use path aliases for imports.
47+ We're going to configure ` "imports" `  in the ` package.json `  to use path aliases for imports.
5548
5649We'll set it to ` "#*": "./*" `  which will allow us to import anything in the root
5750of the repo with ` #<dirname>/<filepath> ` .
5851
5952## Consequences  
6053
6154This 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.
6655
6756If someone wants to use the Epic Stack without Node.js, and their runtime
6857doesn't support ` package.json `  imports (I'm not sure whether other runtimes do
0 commit comments