FutureCake
FutureCake

Reputation: 2953

typescript auto imports not working macos

I have a project and I am adding some typescript but typescript doesnt auto import. And i dont understand why. See below my file structure, tsconfig and an example:

ts config

{ 
    "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
enter image description here

App ts expected import suggestion
enter image description here Here I am expecting to see a suggestion for an import for ImageRowsInitializer from the file called 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 dont get why i am not getting suggestions..
please let me know if more information is needed i am happy to supply :)

Upvotes: 7

Views: 17928

Answers (2)

Zoe L
Zoe L

Reputation: 1500

Select TypeScript Version to be your workspace version, not the vscode version solved the issue on my end. Not sure why though.

enter image description here

Upvotes: 3

Prafull Dhadkar
Prafull Dhadkar

Reputation: 941

Click on TypeScript version in the lower-right corner of VSCode. enter image description here

Now from the command section, select workspace typescript version.

enter image description here

if the error is still not fixed, then - go to settings, Search for "tsdk" click on edit in settings.json and delete the property "typescript.tsdk": "node_modules\\typescript\\lib"

The Third Option is to include all the files under your "Typescript" folder. In your case, typescript is unable to locate all the files in your project. To locate all the files, modify your include array in tsconfig to "include":[ "**/*" ]. It will inform the TS compiler of VSCode to search all the ts files under "Typescript" folder.

This may fix your auto import issue.

enter image description here

Upvotes: 21

Related Questions