TypeScript tsconfig extend compilerOption paths instead of override

Discussão em 'Angular' iniciado por Danilo Bassi, Fevereiro 26, 2025.

  1. Danilo Bassi

    Danilo Bassi Guest

    I'm using NX to host a monorepo with my frontend and my backend. My issue is that I'd like to share my TypeORM entities between my backend and frontend, but on the frontend side, instead of using the main typeorm decorators, I'd like to use the shim decorators.

    currently, I'm doing something like this. On my apps/frontend/tsconfig.json I have this:

    {
    "compilerOptions": {
    "target": "es2022",
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "strict": false,
    "noImplicitOverride": true,
    "noPropertyAccessFromIndexSignature": true,
    "noImplicitReturns": true,
    "noFallthroughCasesInSwitch": true,
    "paths": {
    "typeorm": ["node_modules/typeorm/typeorm-model-shim.js"],
    "@project/dtos/*": ["shared/dtos/src/*"],
    "@project/entities": ["shared/entities/src"],
    "@project/entities/*": ["shared/entities/src/*"],
    "@project/frontend/*": ["shared/frontend/*"]
    }
    },
    "files": [],
    "include": [],
    "references": [
    {
    "path": "./tsconfig.editor.json"
    },
    {
    "path": "./tsconfig.app.json"
    },
    {
    "path": "./tsconfig.spec.json"
    }
    ],
    "extends": "../../tsconfig.base.json",
    "angularCompilerOptions": {
    "enableI18nLegacyMessageIdFormat": false,
    "strictInjectionParameters": true,
    "strictInputAccessModifiers": true,
    "strictTemplates": true
    }
    }



    and on my tsconfig.base.json (at the root of the project)

    {
    "compileOnSave": false,
    "compilerOptions": {
    "rootDir": ".",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "importHelpers": true,
    "target": "es2015",
    "module": "esnext",
    "lib": ["ES2023", "dom"],
    "skipLibCheck": true,
    "skipDefaultLibCheck": true,
    "baseUrl": ".",
    "paths": {
    "@project/dtos/*": ["shared/dtos/src/*"],
    "@project/entities": ["shared/entities/src"],
    "@project/entities/*": ["shared/entities/src/*"],
    "@project/frontend/*": ["shared/frontend/*"]
    }
    },
    "exclude": ["node_modules", "tmp"]
    }



    Note that on the frontend tsconfig file I had to repeat my tsconfig.base.json paths adding the typeorm shims operator. This was done because if I only left "typeorm": ["node_modules/typeorm/typeorm-model-shim.js"], there, I'll be missing all the other paths. Is there any solution to ADD instead of override all the other paths? Because It seems that I will be adding more paths on the future, and I'd like to keep them on the root tsconfig.base.json only.

    Continue reading...

Compartilhe esta Página