Search code examples
typescriptangularsystemjs

How to register a path reference/map for typescript compiler?


I've decided to use my own absolute paths in angular2 in order to avoid this kind of path references:

import someThing from "../../../../../somePath"

I'm using systemjs. My own mappings declared at systemjs.config.js:

var map = {
    ....
    "@services": "app/services",
    "@pipes":    "app/pipes"
};

Everything works fine on the browser, without errors. The files are being imported correctly. But typescript compiler throws some errors:

error TS2307: Cannot find module '@services/SomeService.service'.

But, off course, imports like @angular/core work fine, so it's possible to solve this.

What is the way to indicate typescript compilers these paths are being mapped?


Solution

  • Something like this maybe:

    "paths": {
                "baseUrl": "./",
                "*": [
                    "app/*",
                    "app/main/*"
                ]
          }
    

    The above should be in tsconfig.json