Tips on excluding the index file from VS Code, Intellisense, and Autocomplete

Currently, I am involved in a project that focuses on developing a library. The project includes a lib.ts file located at the root of the workspace, which outlines all the public exports of the library like this:

export * from "./a/a.ts"
export * from "./b/b.ts"
export * from "./c/c.ts"

During development, I heavily rely on VS Code's autocomplete feature (ctrl + space) to assist with organizing and adding imports automatically. However, an issue arises where Intellisense consistently imports from the lib.ts file instead of the original source that houses the export definitions.

For example, if a requires b, when VS Code auto-organizes the imports in a.ts, it would look something like this:

import { b } from "../lib"

export const a = b(1)

This setup leads to circular dependencies during build time, causing confusion for tools like rollup:

  lib.ts -> a/a.ts -> lib.ts -> b/b.ts

My question is, is there a way to instruct VS Code to disregard lib.ts and import b directly from its original source, as shown below?

import { b } from "../b/b"

export const a = b(1)

Answer №1

Dealing with the same issue, I stumbled upon a solution within the settings:

typescript.preferences.autoImportFileExcludePatterns

If you encounter a similar situation, simply include a pattern like this:

{
  "typescript.preferences.autoImportFileExcludePatterns": [
    "../../lib.ts"
  ],
}

With this in place, no imports will be suggested from unwanted lib.ts files.

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

After the build/export process, the NextJS routing fails to function properly when I manually insert the URL

While testing my application on localhost using npm run dev, everything works normally. I can access routes like localhost:3000/settings/account and they render correctly. However, after running npm run build and npm run export, testing with serve -s out a ...

Struggling with Navigation Guard integration in a Vue 3 + Quasar + TypeScript application

Currently, I am developing an application using the Quasar Framework in conjunction with Vue 3 and TypeScript, specifically utilizing the Composition API. My objective is to incorporate a Navigation Guard within my routes.ts file for handling route authent ...

Enhancing Test Components with Providers in "React Testing Library": A Step-by-Step Guide

I am currently working with React-Testing-Library and have set up my main.tsx file with Redux-Toolkit and React-Router wrappers like this: ReactDOM.createRoot(document.getElementById("root")!).render( <React.StrictMode> <Provider s ...

The abundance of options in WebStorm's code completion for Node can be overwhelming

I recently finished a project using NodeJS and TypeScript. I made sure to install the type definition files with 'tsd install node'. The code begins with the following lines: var http = require('http'); var server = http.createServer(. ...

What could be causing my SectionList to occasionally display only a single section?

I'm facing a problem with the SectionList component where it occasionally fails to display all sections, only rendering the first one. After some debugging, I may have found a solution, but I'm unsure why it resolves the issue. While my page con ...

Unique: "Unique One-Step Deviation in Date Comparison"

A Little Background Information: I am working with data points that span from the current day to 5 days ahead, in 3-hour intervals (such as 10pm, 1am, 4am, 7am...). My goal is to organize these data points into arrays sorted by date, with each array repre ...

When you click on one checkbox, the angular2-multiselect dropdown automatically selects all the boxes

<angular2-multiselect [data]="sortedDataList | OrderBy : 'clientName'" [(ngModel)]="selectedItem[sortedDataList.clientId]" [settings]="dropdownSettings" name="multiSelect" (onSelect)="onItemSelect($event, ...

Tips for verifying that parameters possess designated characteristics in TypeScript

How can I ensure that data2 and data3 work correctly, while data1 triggers an error if the data type is not specified as shown in the code below? I need to validate that when a user enters params like {name: 'aa', age: 20}, it should throw an er ...

Definition of assignability for intersection types

Exploring the concept of intersection types, we can find a definition in https://github.com/microsoft/TypeScript/pull/3622 When A & B is assignable to X, it means that either A is assignable to X or B is assignable to X. type A = {x:1} type B = {y:1} ...

Implementing React: Dynamically Assigning a className to a New Component

I'm attempting to include a className property in a newly created component in the following way: const component = <Icons.RightArrowIcon /> // I intend to add a className to this component // Then... // ... return ( <>{component}&l ...

What is the best way to initiate an HTTP POST request in Ionic 2 (typescript) while including parameters in the form of a multipart/form-data

My webservice, which is generated with the Drupal 7 plugin Service, accepts requests on ''. These requests are checked against an 'api-key' variable, acting as a password. When attempting to connect to the service using my Ionic2/Cordo ...

Issue with nestjs build due to ts-loader module in dev-dependency

I've encountered a Module Error with ts-loader during a docker build ERROR [6/6] RUN nest build 3.9s ------ > [6/6] RUN ...

Creating an array of objects with string keys in JavaScript can be achieved by defining an array

In order to simulate a response from the server, I would like to use keys such as 1.0.0 instead of default indexes. This will result in something like the example below: https://i.sstatic.net/JUzjf.png I attempted using { 'versions': [ '1. ...

Error message encountered when using Vue and typescript: "TypeError: Object prototype may only be an Object or null: undefined"

Encountered a TypeError: Object prototype may only be an Object or null: undefined I ran into an issue while working on my project. I'm utilizing vuejs, typescript, and jest. Despite having simple code, I encountered an error when trying to unit tes ...

VS Code couldn't locate a definition for the function 'myMethod'

For some reason, I am unable to find a definition for 'myMethod' in VS Code. In my angular projects, after importing one project into VS Code, I can easily navigate to definitions using the 'F12' key. However, when I import another pro ...

Submit the request when the fileReader's onload event is triggered

Do you have any suggestions on how to improve my fileReader for uploading images? I am currently facing an issue where multiple requests are being sent to the server when there are more than 1 image due to a for loop. How can I modify my code to address ...

Using FullCalendar within an Ionic3 framework powered by Angular 4

Is there a way to initialize fullCalendar in an event (such as a click) on Ionic 3, using Angular 4? This code works when the calendar options are set in a variable: calendarOptions: Object = { fixedWeekCount: true, editable: true }; However, ...

A guide on updating from the old version to the new version of Permission Handler

I have an old permission handler code that needs to be updated to work with the latest version of pubspec.yaml. Can anyone provide guidance on how to modify the code below for compatibility with the latest version? if (Platform.isAndroid) { Permissio ...

Tips on accessing the formControl element within a formBuilder array

Is there a way to retrieve the value from mat-autocomplete when using formControlName? It seems that mat-autocomplete doesn't work in this scenario. <mat-form-field> <mat-label>...</mat-label> <input type="text ...

Using --watch in vscode while debugging a NestJS application with Docker causes the debugging process to pause whenever a file is

When debugging a typescript nestjs application in Visual Studio code using the Docker extension and running it in watch mode, I encountered an issue that I cannot seem to resolve. The application is mounted in a docker container through a volume. Everythi ...