#Any suggestions on how I can get rid of the '../../' in this import path?

6 messages · Page 1 of 1 (latest)

boreal violet
#

So I have imports of the form:

import type { LetterData } from '../../data/letters';

How do I get rid of the '../../', etc? I see both "+" and "@" signs in use elsewhere but I'm not sure what they are, nor which docs to look for.

inner heath
#

@boreal violet It depends on the context. To do this you need both 1) to tell TS about this mapping (the paths property) and 2) you need something to actually resolve the mapping when your code runs.

#

If it's a UI packaged by a bundler, they'll have config for that (e.g. for Vite it's resolve.alias)

#

If you're writing a library I think this ends up being a bad idea

#

Personally, I try to avoid this nowadays and try to structure my code so that I don't have to do big ../.. imports - if related files are grouped together you can usually minimize it.

boreal violet