VS代码中的打字稿类型定义

时间:2019-01-31 05:35:16

标签: typescript visual-studio-code typescript-typings

我遇到了一个问题,其中使用@types使用npm安装的类型在Intellisense中显示为建议,但随后收到错误“找不到名称类型”。

作为一个例子,我正在使用nodemailer,并且还为其安装了类型定义。当我没有明确说明类型时,就可以正确检测到该类型(我将鼠标悬停在正确标识为Mail的“ transporter”上)

enter image description here

当我键入内容时,它也可以正确提示Intellisense中的类型:

enter image description here

但是,一旦我明确指出类型,我就会收到错误消息:

enter image description here

我没有在tsconfig中声明typeRoot,因为它使用的是自TS2和@types以来可用的默认结构。

 {
    "compilerOptions": {
        "allowJs": true,
        "checkJs": false,
        "noImplicitAny": true,
        "strictNullChecks": true,
        "removeComments": true,
        "sourceMap": false,
        "outDir": "./dist",
        "target": "ESNext",
        "module": "CommonJs"
    },
    "include": ["src/**/*"],
    "exclude": [
        "node_modules",
        "**/*.spec.ts"
    ]
}

有人知道如何使用@types的类型显式定义变量类型吗?

0 个答案:

没有答案
相关问题