docs: documet support for type aliases (#11117)

This commit is contained in:
Shahed Nasser
2025-01-30 09:09:29 +02:00
committed by GitHub
parent e98d3c615e
commit 332ef06534
3 changed files with 59 additions and 0 deletions

View 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"
```

View File

@@ -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",

View File

@@ -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",