docs: documet support for type aliases (#11117)
This commit is contained in:
46
www/apps/book/app/learn/conventions/ts-aliases/page.mdx
Normal file
46
www/apps/book/app/learn/conventions/ts-aliases/page.mdx
Normal file
@@ -0,0 +1,46 @@
|
||||
export const metadata = {
|
||||
title: `${pageNumber} Using TypeScript Aliases`,
|
||||
}
|
||||
|
||||
# {metadata.title}
|
||||
|
||||
By default, Medusa doesn't support TypeScript aliases in production.
|
||||
|
||||
If you prefer using TypeScript aliases, install following development dependencies:
|
||||
|
||||
```bash npm2yarn
|
||||
npm install --save-dev tsc-alias rimraf
|
||||
```
|
||||
|
||||
Where `tsc-alias` is a package that resolves TypeScript aliases, and `rimraf` is a package that removes files and directories.
|
||||
|
||||
Then, add a new `resolve:aliases` script to your `package.json` and update the `build` script:
|
||||
|
||||
```json title="package.json"
|
||||
{
|
||||
"scripts": {
|
||||
// other scripts...
|
||||
"resolve:aliases": "tsc --showConfig -p tsconfig.json > tsconfig.resolved.json && tsc-alias -p tsconfig.resolved.json && rimraf tsconfig.resolved.json",
|
||||
"build": "npm run resolve:aliases && medusa build"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
You can now use TypeScript aliases in your Medusa application. For example, add the following in `tsconfig.json`:
|
||||
|
||||
```json title="tsconfig.json"
|
||||
{
|
||||
"compilerOptions": {
|
||||
// ...
|
||||
"paths": {
|
||||
"@/*": ["./src/*"]
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Now, you can import modules, for example, using TypeScript aliases:
|
||||
|
||||
```ts
|
||||
import { BrandModuleService } from "@/modules/brand/service"
|
||||
```
|
||||
@@ -109,6 +109,8 @@ export const generatedEditDates = {
|
||||
"app/learn/installation/page.mdx": "2025-01-27T08:45:19.029Z",
|
||||
"app/learn/fundamentals/data-models/check-constraints/page.mdx": "2024-12-06T14:34:50.384Z",
|
||||
"app/learn/fundamentals/module-links/link/page.mdx": "2025-01-06T09:27:25.604Z",
|
||||
"app/learn/conventions/ts-aliases/page.mdx": "2025-01-23T15:01:15.403Z",
|
||||
"app/learn/fundamentals/workflows/store-executions/page.mdx": "2025-01-24T12:09:24.087Z",
|
||||
"app/learn/fundamentals/plugins/create/page.mdx": "2025-01-28T07:08:05.418Z",
|
||||
"app/learn/fundamentals/plugins/page.mdx": "2025-01-22T10:14:10.433Z",
|
||||
"app/learn/customization/reuse-customizations/page.mdx": "2025-01-22T10:01:57.665Z",
|
||||
|
||||
@@ -500,6 +500,17 @@ export const sidebar = sidebarAttachHrefCommonOptions([
|
||||
title: "Storefront Development",
|
||||
chapterTitle: "Storefront",
|
||||
},
|
||||
{
|
||||
type: "category",
|
||||
title: "Conventions",
|
||||
children: [
|
||||
{
|
||||
type: "link",
|
||||
title: "Type Aliases",
|
||||
path: "/learn/conventions/ts-aliases",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
type: "link",
|
||||
path: "/learn/debugging-and-testing",
|
||||
|
||||
Reference in New Issue
Block a user