如何在 JS 项目中使用自定义类型

sua*_*kim 9 visual-studio-code typescript-typings checkjs

我正在一个 Electron 项目中使用checkjs: trueset in myjsconfig.json并在ProjectRoot/typings/index.d.ts.

我希望在所有 JS 文件中都可以使用这些类型。不幸的是,我必须手动引用它们:

在此处输入图片说明

如果没有手册参考,它将无法识别类型:

在此处输入图片说明

我的项目结构如下所示:

在此处输入图片说明

这是typings/index.d.ts的内容:

interface LauncherItem {
    name: string,
    icon: string,
    cmd: string,
    args: string,
}

interface AppConfig {
    items: LauncherItem[],
    appIconSize: number,
}
Run Code Online (Sandbox Code Playgroud)

jsconfig.json

{
    "compilerOptions": {
        "target": "es6",
        "checkJs": true
    },
    "typeAcquisition": {
        "include": [
            "./typings/index.d.ts"
        ]
    },
    "include": [
        "**/*.js",
        "*.d.ts"
    ]
}
Run Code Online (Sandbox Code Playgroud)

不确定是否通常需要显式typeAcquisition和包含*.d.ts。它们只是我测试的结果,但显然不起作用......