Tips for resolving aliases in tsconfig.app.json when dealing with multiple source directories in WebStorm

When it comes to generating source files, I do things a bit differently and create some of them outside of the usual src directory. Here's how my structure looks:


- project
  - generated
    - $ui-services
        some-other.service.ts
  - src
    - app
      - $ui-services
          some.service.ts

To make this setup work, I made sure to specify the following in tsconfig.app.json:


"compilerOptions": {
  ...
  "paths": {
    ...
    "@ui-services/*": ["app/$ui-services/*", "../generated/$ui-services/*"],
    ...
  }
},
"include": [
  "./**/*.ts",
  "../generated/**/*.ts"
]

With this configuration, I can now import SomeService into SomeOtherService like so:


import {SomeService} from '@ui-services/some.service';

Although everything seems to be working as intended, I've encountered an issue with WebStorm where it fails to properly resolve the aliases in some-other-service.ts.

I've attempted to mark both folders as Resource Root as suggested by some, but unfortunately, that didn't provide a solution.

Is there a way for me to resolve this mismatch in file resolution across directories?

Answer №1

If you encounter the same problem while using tsc in the command line, it is likely due to how the Typescript compiler operates. It looks for the nearest tsconfig.*.json file that the current file is a part of, scanning folders from the file directory up to the project root. In the case of

generated/$ui-services/some-service.service.ts
, the closest configuration file would be the tsconfig.json located at the root of the project. However, this configuration does not have any aliases defined, leading to TS2307 errors and unresolved members. To resolve this issue, you can copy the path mappings to the root configuration file like so:

"paths": {
      "@ui-services/*": ["src/app/$ui-services/*", "generated/$ui-services/*"]
    },

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

A guide to incorporating dhtmlx scheduler into your Angular 4 project

Currently, I am utilizing dhtmlx scheduler to handle my events. While I was able to import the necessary js files successfully, I have encountered an issue when it comes to saving data in the database. My backend is built using Spring Boot framework. Can ...

How to eliminate parameters from the URL in Ionic 2 with Angular 2

Basically, in my application, when a user receives an email notification with a hyperlink to open a specific record based on an ID number, the URL looks like this: https://myappserver.com/?aid=12343551 So, after the user opens the record, I'm wonder ...

What is the most effective method to query Prisma using a slug without utilizing a React hook?

Retrieve post by ID (slug) from Prisma using getStaticProps() before page generation The challenge arises when attempting to utilize a React hook within getStaticProps. Initially, the plan was to obtain slug names with useRouter and then query for a post ...

Exploring the world of Unicode in Angular

I need to search for pokemon and retrieve all Pokémon results (with the accent included) This is my array: let games = ['The Legend of Zelda', 'Pokémon', 'Chrono Trigger'] This is how I am attempting to do it: Using HTML ...

The 'Key' identifier is not valid for indexing the 'Object' data type

Currently attempting to incorporate functional pluck with a specific sound type, but encountering an issue: function extract<Object extends {}, Key = keyof Object>(key: Key): (o: Object) => Object[Key] { return object => object[key]; } Erro ...

Encountered a bug in the findUnique function within the services of a Nest JS and Prisma project

I have a question about using Prisma with Nest. I keep encountering this error: src/modules/auth/auth.service.ts:28:63 - error TS2322: Type 'UserWhereUniqueInput' is not assignable to type 'string'. 28 const user = await this.prisma ...

Customizing the appearance of a component using parameters provided by a separate component

I've created a file-uploader component with the following HTML structure: <label class="uploader" ondragover="return false;" [class.loaded]="loaded" [style.outlineColor]="dragging ? activeColor : baseColor" (dragenter)="handleDragEnter()" (dragle ...

What are the steps to configure Auth0 for an Angular application?

I'm having trouble implementing Auth0 into my angular app. After configuring it on [https://manage.auth0.com/dashboard/], clicking the save changes button results in this error: Error!Payload validation error: 'Object didn't pass validatio ...

Dealing with Errors in Angular 8: Best Practices for Handling Response Errors

When an error is thrown from the WEB API, I do not receive any response and the debugger does not hit. However, in case of success, I do get a response and the debugger hits. All I want is to receive an error response and have the debugger hit every time, ...

When the Angular+gsap3 animation fails to trigger on click

app.component.html <div #animate class="main"> <div id="go" (click)="click()" class="box1"></div> <div class="box"></div> <div class="box"></di ...

I'm receiving an error message stating "mongoose.connect is not a function" while attempting to establish a connection with mongoose. Can you help me troub

I'm a beginner in Node.js and I'm currently working on creating a node/express/mongoose server app using TypeScript. Below is my app.ts file: // lib/app.ts import express from 'express'; import * as bodyParser from 'body-parser&a ...

Tips for adding a class to the end of the DOM class

Greetings! I'm currently working with the code below: for ( let x: number = 0; x < this._vcr.element.nativeElement.querySelectorAll(".ui-steps-item").length; x++) { let className: any = this._vcr.element.nativeElement.querySelectorAll( ...

Deriving a universal parameter from a function provided as an argument

My function can take in different adapters along with their optional options. // Query adapter type 1 type O1 = { opt: 1 } const adapter1 = (key: string, options?: O1) => 1 // Query adapter type 2 type O2 = { opt: 2 } const adapter2 = (key: string, opti ...

Tips for implementing mixins in a Nuxt.js application using the nuxt-property-decorator package

Recently, I worked on a project where I utilized Nuxt.js with TypeScript as the language. In addition, I incorporated nuxt-property-decorator. I'm currently trying to grasp the concept of the 'mixins' property in the code snippet below: mi ...

Mastering ngClass for validation in Angular 2: Step-by-step guide

I am facing an issue with a form I have created where I applied ngclass to display an error when the form value is missing. However, the error is showing up when the form is initially loaded. It seems that by default, my input tag is invalid when the form ...

Which is better for scrolling in Angular 2+: using HostListener or window.pageYOffset?

Which syntax is best for maximizing performance in Angular 2+? Is it necessary to use HostListener, or is it simpler to obtain the scroll position using the onscroll window event and pageYOffset? @HostListener('window:scroll', ['$event&ap ...

The way Angular Material Tables Sort Alphanumeric Values

While working with the Angular Material Table, I encountered an issue where the ascending sort order is not as expected. Here's the scenario: Let's consider 5 codes: F1, F2, F5, F9, F10. The default sorting order in Angular Material Table is: ...

Tips for providing certificate key file during the deployment of a cloud function?

Within my TypeScript file, the following code is present: import * as admin from 'firebase-admin' import * as functions from 'firebase-functions' const serviceAccountKey = "serviceAccountKey.json" const databaseURL = "https://blahblah. ...

What is causing these TypeScript type assertions to go unnoticed?

While reviewing type assertions, I noticed something interesting about the last three variable assignments - they don't produce errors. It's perplexing because I thought I was trying to change 'helo' into 'hello', which should ...

Subscription to Observable content failed to run

When a submit button is clicked inside the component HTML, it triggers a function called addCollaborators(). The code for this function can be found below: component.ts emails: string[] = []; constructor(public userService: UserService) {} // Function ...