How to declare path aliases in Typescript

Defining path aliases using webpack can save you a lot of headache when it comes to imports, but you must also let Typescript know about them.

Following my [previous post](https://graffino.com/til/FRXaL59FzW-folder-aliases-using-webpack) on declaring path aliases using webpack, you can configure your **`tsconfig.json`** file to in order to be able to use those aliases in Typescript like so:

```js
{
  ...
  "paths": {
    "@/*": ["./src/*"],
    "images/*": ["./assets/images/*"],
  },
  "include": [
    ...
  ],
}
```

Of course, all paths for defined aliases must be reachable by Typescript. You can check [this post](https://graffino.com/til/hEvDjQa4au-how-to-import-images-in-typescript) out if you are not sure how to do that.


Otherwise, we are going to get this error:
```ts
Cannot find module 'images/[your module]' or its corresponding type declarations.
```

Denisa Halmaghi
07 Dec 2021
« Back to post