打字稿自动导入不起作用 macos [英] typescript auto imports not working macos

查看:56
本文介绍了打字稿自动导入不起作用 macos的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个项目,我正在添加一些打字稿,但打字稿不会自动导入.我不明白为什么.请参阅下面我的文件结构、tsconfig 和示例:

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 配置

{ 
    "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
}

文件结构

应用 ts 预期导入建议
在这里,我期待看到从名为 images-row.ts 的文件中导入 ImageRowsInitializer 的建议.

App ts expected import suggestion
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 :)

推荐答案

点击 VSCode 右下角的 TypeScript 版本.

Click on TypeScript version in the lower-right corner of VSCode.

现在从命令部分,选择工作区打字稿版本.

Now from the command section, select workspace typescript version.

如果错误仍未修复,则 -前往设置,搜索tsdk"单击 settings.json 中的编辑并删除属性typescript.tsdk":node_modules\\typescript\\lib"

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"

第三个选项是包含Typescript"下的所有文件.文件夹.在您的情况下,打字稿无法找到您项目中的所有文件.要找到所有文件,请将 tsconfig 中的 include 数组修改为 "include":[ "**/*"].它会通知VSCode的TS编译器搜索Typescript"下的所有ts文件.文件夹.

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.

这篇关于打字稿自动导入不起作用 macos的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆