Skip to content

Latest commit

 

History

History
30 lines (21 loc) · 626 Bytes

path-aliases.md

File metadata and controls

30 lines (21 loc) · 626 Bytes

How to use path aliases with TypeScript in Node.js

In order to avoid the following problem:

import { IPriceData, IVolumeData } from "../../../models/index";

import { connectToDatabase } from '../../../lib/mongodb';

You can add an alias to the tsconfig.json file:

"baseUrl": ".",
"paths": {
  "@models/*": ["models/*"],
  "@lib/*": ["lib/*"]
}

So that the imports now look:

import { IPriceData, IVolumeData } from "@models/index";

import { connectToDatabase } from '@lib/mongodb';

References: