Having trouble with TypeScript auto imports on macOS?

I have a new project where I am incorporating TypeScript, but for some reason the auto import feature is not working as expected. Below you can find my file structure, tsconfig file, and an example:

tsconfig.json

{ 
    "compilerOptions": { 
        "target": "es6",
        "module": "commonjs",
        "declaration": false,
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "sourceMap": true,
        "pretty": true,
        "allowUnreachableCode": false,
        "allowUnusedLabels": false,
        "noImplicitAny": true,
        "noImplicitReturns": false,
        "noImplicitUseStrict": false,
        "outDir": "../Js/",
        "baseUrl": "./",
    },
    "include":[ 
       "*.ts"
    ],
    "compileOnSave": true
}

File Structure
https://i.sstatic.net/ggRjpm.png

Expected Import Suggestion in App.ts
https://i.sstatic.net/NuJN3.png I am anticipating an import suggestion for ImageRowsInitializer from the file named images-row.ts.

images-row.ts

export class ImageRowsInitializer {
    
    private image_rows : ImagesRow[];
    
    constructor() {
        const htmlImageRows = document.getElementsByClassName("row-container");
        for (let i = 0; i < htmlImageRows.length; i++) {
            const imagerow = htmlImageRows[i];
            this.image_rows.push(new ImagesRow(imagerow as HTMLElement));
        }
    }
}

I am puzzled why the suggestions are not showing up...
Please inform me if more details are required, I would be glad to provide them :)

Answer №1

To resolve the error in your TypeScript project, follow these steps: Click on the TypeScript version located in the lower-right corner of VSCode. https://i.sstatic.net/1E0uV.png

Next, navigate to the command section and choose the workspace TypeScript version.

https://i.sstatic.net/3K1HH.png

If the issue persists, proceed with the following steps - Access your settings, Look for "tsdk", Open the settings.json file by clicking on edit and remove the property

"typescript.tsdk": "node_modules\\typescript\\lib"

The third option involves including all files within your "TypeScript" folder. If TypeScript is struggling to locate the necessary files in your project, Adjust the include array in tsconfig to "include":[ "**/*" ]. This configuration will prompt the TS compiler in VSCode to search for all .ts files within the "TypeScript" folder.

Implementing this may resolve any auto import issues you are encountering.

https://i.sstatic.net/9lQeY.png

Answer №2

Choosing TypeScript Version as the workspace version instead of the vscode version helped resolve the problem for me. The reason behind this solution remains unclear, though.

https://i.sstatic.net/EUSrI.png

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

The TypeScript declarations for Forge Viewer do not include typings related to Profiles

I've been utilizing typescript definitions for Forge from the DefinitelyTyped repository: https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/forge-viewer However, there seems to be a lack of typings, particularly those associated wi ...

Add information to an array by simply modifying the existing data that shares the same key/value pair

Currently, I am working on the front-end of a delivery web application. On one of the screens, I have implemented a Google map that allows the company owner to track their delivery riders in real-time. The process of implementing the map itself was quite s ...

Determine the data type based on the object property

Can a versatile function be created to automatically determine the type based on an "external" object property? Consider the following scenario: const resolversMap: { overallRankingPlacement: (issuer: number, args: Record<string, any>, context: Re ...

What is causing VSCode to not locate the existing header file in the workspace?

Software version: VSCode 1.85.2 Operating System: Windows 11 with Ubuntu 20.04 running on WSL 2 I am currently working on a project for the MIT 6.S081 Lab and have successfully built and run it. However, I am encountering an issue where header files incl ...

Error building Angular module occurred while executing the project

Recently, I got an Angular template from this site: After successfully running npm install, I encountered an error when trying to run ng serve: ./src/styles.scss - Error: Module build failed (from ./node_modules/mini-css-extract-plugin/dist/loader.js): Mo ...

Discovering the category for ethereum, provider, and contract

My current interface looks like this: interface IWeb3 { ethereum?: MetaMaskInpageProvider; provider?: any; contract?: any; }; I was able to locate the type for ethereum using import { MetaMaskInpageProvider } from "@metamask/providers", ...

Minimize the count of switch cases that are not empty

How can I optimize the number of cases in my switch statement to align with SonarQube recommendations? Currently, I have 37 cases in a switch statement, but SonarQube recommends only 30. I believe that my code is functioning correctly, and the issue lies ...

What is a simple method to convert TypeScript to JavaScript?

Is it possible to eliminate TypeScript-specific keywords from a JavaScript file without using the tsc command, while ensuring that the file remains readable by humans and maintains JSX syntax? ...

Unable to launch Google Cloud Functions when using multiple files

When attempting to deploy some function scripts to Firebase Functions, I encountered an error. The error message reads: Function failed on loading user code. Error message: Code in file lib/index.js can't be loaded. Did you list all required modules ...

Resolving TS2304 error using Webpack 2 and Angular 2

I have been closely following the angular documentation regarding webpack 2 integration with angular 2. My code can be found on GitHub here, and it is configured using the webpack.dev.js setup. When attempting to run the development build using npm start ...

Utilizing React-Input-Mask (written in TypeScript) to conceal Material UI input within Formik forms

Issue with Formik Input and TextField Type Error <InputMask mask="99/99/9999" value={formik.values.phone} onChange={formik.handleChange} onBlur={formik.handleBlur} > {(inputProps: Pro ...

Present various image formats encoded in base64 retrieved from the backend API using Angular 7

I have an API that provides images in base64 format, which can be in various file formats like .png, .jpg, .svg, etc. I am looking to display these images in my application using: <img *ngIf="imageBase64" [src]="imageBase64 ? ('data:image/svg+xml ...

A TypeScript function that returns a boolean value is executed as a void function

It seems that in the given example, even if a function is defined to return void, a function returning a boolean still passes through the type check. Is this a bug or is there a legitimate reason for this behavior? Are there any workarounds available? type ...

The TypeScript compiler has encountered an error (TS2339) indicating that the property 'id' does not exist on the type 'User'

Hi there, I'm new to TS and this is my first question here. I am encountering an error that says 'property 'id' does not exist on type 'User''. Could someone please explain why this error is happening and how I can fix it ...

Angular 7 TypeScript code not updating value

UPDATE: I'm having trouble with my code not updating the selected value with the new one entered in the input field "newVb". The error message says 'this.newVarde' is undefined when it reaches the line 'this.selectedVarde = this.newVard ...

Craft dynamic SVG components using TypeScript

Looking to generate a correctly formatted SVG element using TypeScript: createSVGElement(tag) { return document.createElementNS("http://www.w3.org/2000/svg", tag); } Encountering an issue with tslint: Error message: 'Forbidden http url in str ...

What causes certain files to sporadically duplicate themselves in Visual Studio Code?

While using vscode for NodeJS development, I have noticed that certain files seem to duplicate themselves sporadically. Why is this happening and what steps can I take to resolve it? I am unsure of how to tackle this issue... ...

Encountering a TypeError when using Webpack and ts-loader to bundle a third-party library

While everything compiles and bundles successfully, a TypeError is encountered in the browser: "box2dweb_commonjs_1.default is undefined." No errors occur when starting webpack-dev-server and reviewing the bundle at http://localhost:8080/webpack-dev-serv ...

Issue encountered while attempting to launch Angular2 project

Having trouble running my Angular2 project, every time I try to use the ng serve command I get an error: Here is the link: https://i.sstatic.net/SYENX.png I've installed angular 2 using angular-cli with the following steps: 1. sudo npm install -g ...

Experiencing compatibility issues with NextAuth and Prisma on Netlify when using NextJS 14

While the website is functioning correctly on development and production modes, I am encountering issues when testing it on my local machine. After deploying to Netlify, the website fails to work as expected. [There are errors being displayed in the conso ...