代码之家  ›  专栏  ›  技术社区  ›  suamikim

如何在JS项目中使用自定义键入

  •  4
  • suamikim  · 技术社区  · 6 年前

    我在一个电子项目中工作 checkjs: true 设置在我的 jsconfig.json 并在 ProjectRoot/typings/index.d.ts

    我想在所有的JS文件中都提供这些打字。不幸的是,我不得不手动引用它们:

    enter image description here

    enter image description here

    我的项目结构如下所示:

    enter image description here

    以下是 打字/索引 :

    interface LauncherItem {
        name: string,
        icon: string,
        cmd: string,
        args: string,
    }
    
    interface AppConfig {
        items: LauncherItem[],
        appIconSize: number,
    }
    

    以及 jsconfig.json文件 :

    {
        "compilerOptions": {
            "target": "es6",
            "checkJs": true
        },
        "typeAcquisition": {
            "include": [
                "./typings/index.d.ts"
            ]
        },
        "include": [
            "**/*.js",
            "*.d.ts"
        ]
    }
    

    typeAcquisition *.d.ts 通常是必要的。它们只是我测试的结果,但显然不起作用。。。

    0 回复  |  直到 6 年前