Automatically updating references of TypeScript classes to new locations in Visual Studio Code: A hassle-free guide

Currently using Visual Studio Code for an Angular project, I am in the process of refactoring by moving some interface files from the app to a library. However, when I try to drag and drop the file in VSC, only the references in files that use relative paths are updated. The other references that import the interface using "@core/models" are not being changed.

"@core/models"

For example, if I move the "user.model.ts" file, the references like

import { User } from '../../models/user';
will be updated to
import { User } from '../../../../../../libs/mylib/src/lib/models/user';
, but those referencing it as
import { User} from '@core/models';
remain untouched.

If I manually select the interface name, right-click, and choose "Find all references," VSC displays all references correctly in the list. With around 300 references to that file, doing this task manually is not ideal.

Answer №1

It's uncertain whether VSCode has the capability to automatically and consistently perform this task.

To address this issue, I suggest conducting a global search and replace through either the command line or within VSCode itself. By doing so, you can depend on the TypeScript compiler to flag any incorrect imports.

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

Angular navigation did not work as expected

Created a basic webpage using Angular CLI version 8.3. The issue is as follows: For example: www.domainname.com is working fine. www.domainname.com/basicprinciples will work if visited through the main page, but it does not work when directly visiting w ...

Is there a way to define a type for a React component using TypeScript?

Is it possible to pass a custom React component as a property to another component? event-logistics.tsx // component name import { DateIcon } from "../../ui/icons/DateIcon"; import LogisticsItem from "./logistics-item"; ...

Angular 2 is throwing an error, stating that Observable is not defined

I'm currently working with Observable and ChangeDetectionStrategy to notify other components about any changes that occur. However, I am encountering an issue where the Observable object addItemStream is coming up as undefined. Can anyone spot what mi ...

Tips for Handwriting combineReducer using Typescript?

Learning redux with typescript has been quite a journey for me. I've successfully implemented combineReducers in my code: export const reducerBase= combineReducers({ stateA: reducerA, stateB: reducerB, stateC: reducerC }); Everything was going ...

Parent method instantiating child class instance

My code includes a parent class and a child class, with the parent class containing a modify function: const modify = (data) => { const newData = data // changes newData in some way return newData } class Parent { constructor(data) { this.d ...

How to set the type of an object property to a string based on a string from an array of strings in TypeScript

Great { choices: ['Bob', 'Chris', 'Alice'], selectedChoice: 'Alice', } Not So Good { choices: ['Bob', 'Chris', 'Alice'], selectedChoice: 'Sam', } I've been exp ...

Learning the process of interpreting form data in Node.js

I'm currently working with Ionic Angular on the frontend and I am trying to send a formdata that includes a file along with two strings. It seems like the data is being sent successfully, but I am unsure how to access and read this information on the ...

Unable to locate a declaration file for the 'mymodule' module

After attempting to import my test module by installing it with npm i github.com/.../..., the code is functioning properly. However, when I opened it in VSCode, an error message popped up: Could not find a declaration file for module 'estrajs'. & ...

What could be causing the HTTP response Array length in Angular to be undefined?

Currently, I am facing an issue while retrieving lobby data from a Spring Boot API to display it in my Angular frontend. After fetching the data and mapping it into an object array, I encountered a problem where the length of the array turned out to be und ...

Can you hover over the closing tag in HTML to preview the corresponding opening tag?

Is it possible to display a preview of the opening tag when hovering over a closing tag? For instance, if I hover over </div>, I would like to see <div class="card"> ... ... </div> The reason for requesting this feature i ...

The mkdir function has encountered an invalid argument error with code EINVAL

I am encountering an issue with my Angular app build command. I have npm version 6.14 and node version 14.15.4 installed on my Windows 7 32-bit system. The error message I receive when running 'npm run build' is: 95% emitting index-html-webpack-p ...

Determine the route path during the ongoing navigation event in Angular 8 using NavigationStart

Looking for a way to retrieve the router path during a NavigationStart event in Angular 8 this.router.events .pipe(filter(event => event instanceof NavigationStart)) .subscribe((event: NavigationStart) => { // need help gett ...

Adjusting box width based on device type: desktop and mobile

I'm currently working on a form that includes several mat-form-fields. I have set the width of these items to 750px, but this does not work well for mobile devices. I am trying to figure out how to make the form or mat-form-field automatically adjust ...

Creating an npm library using TypeScript model classes: A step-by-step guide

Currently, I am working on a large-scale web application that consists of multiple modules and repositories. Each module is being developed as an individual Angular project. These Angular projects have some shared UI components, services, and models which ...

Tips for incorporating asynchronous page components as a child element in next.js?

Utilizing the latest functionality in next.js for server-side rendering, I am converting my component to be async as per the documentation. Here is a simple example of my page component: export default async function Home() { const res = await fetch( ...

Utilizing the TypeScript compiler through an NPM module command

I am currently working on a project written in TypeScript and utilizing a task runner for building purposes (such as Gulp, Jake, etc.). The TypeScript compiler that I am using has been installed from NPM through the following command: npm install typescri ...

The Router.url function consistently returns a forward slash instead of the actual current URL

I'm puzzled as to why, in this scenario, my current URL shows '/' when I refresh the page on '/component'. Shouldn't it show '/component' instead? However, the URL appears correct in the this.router array... Here ...

Refactor TypeScript in Visual Studio Code: Relocate class from one file to another (already existing) file

One common task when reorganizing a project with numerous classes is to transfer certain classes to an already existing file. After exploring various vscode features and extensions, I have not come across any refactoring tool that allows for this specific ...

Navigating through sections in NextJS-14: Utilizing useRef for seamless scrolling

In the past, I had developed an older portfolio website using Vite React + TS and implemented useRef for scrolling to sections from the Navbar. Now, my goal is to transition this portfolio to NextJS 14. I transferred my old components and style folders in ...

Utilizing TypeORM to selectively choose data in OneToMany relationships

I am looking to create a TypeORM query that pulls data from the database. Specifically, I want to retrieve all clients who have made a purchase but have not initiated a return. Here is the structure of the database: Clients: Id (Int, primary column) Purc ...