How to use custom typings in JS project

1.1k Views Asked by At

I'm working in an Electron project with checkjs: true set in my jsconfig.json and have created a file with custom typings in ProjectRoot/typings/index.d.ts.

I'd like to have those typings available in all JS files. Unfortunately I have to reference them manually:

enter image description here

Without the manual reference, it won't recognize the type:

enter image description here

My Project structure looks like this:

enter image description here

Here's the content of typings/index.d.ts:

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

interface AppConfig {
    items: LauncherItem[],
    appIconSize: number,
}

And jsconfig.json:

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

Not sure if the explicit typeAcquisition and include of *.d.ts is usually necessary. They're just a result of my tests but obviously didn't work...

0

There are 0 best solutions below