How to add absolute imports

Hey! I was looking for absolute imports to follow TypeScript’s path and I found this from 2018.

My question is if it is still relevant or there is another approach?

I vaguely remember doing this and found this in my tsconfig.json

"paths": {
  /* Support absolute /imports/* with a leading '/' */
  "/*": ["*"]
},

That gives me the ability to do this:

image

Is that what you want?

Not really, I’m aware of TypeScript’s path, but Meteor does not use that for it’s imports, so if I specify a path within a folder it will not work.

What do you mean by “Meteor… it’s imports”? Can you give an example of what does and doesn’t work?

Let’s say I have a folder struct of /shared/db/... and I want to import it as _db/..., that’s possible in TypeScript but not in Meteor.

    "paths": {
      "_db/*": ["./shared/db/*"]
    },

OK, I see your problem. It seems that my "/*": ["*"] is needed for VSCode, but Meteor ignores it and allows absolute imports anyway.

If I try to change my paths similar to your example:

    "paths": {
      /* Support absolute /imports/* with a leading '/' */
      "/*": ["*"],
      "_db/*": ["./imports/collections/*"]
    },

And then try this:

import { companySettings, } from '_db/companySettings';

VSCode is happy, but Meteor doesn’t build.

I found these posts - maybe try the babel-plugin-module-resolver module:

That’s a strange coincidence. I’ve spent quite some time yesterday trying to configure Meteor, VSCode, TypeScript, ESLint, etc. for a new project. I couldn’t find a way to use TypeScript aliases in Meteor, unfortunately. That would have been pretty neat!

Moreover, eslint-plugin-import causes various issues too and I had to stop using it, which is sad. I played with TypeScript support for managing imports, but I was then stuck with managing types which I do not use. I do feel ill-equipped for managing imports elegantly.