Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

visual studio code - 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 :)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...