Thursday, 21 June 2018

Add custom typings file in a JavaScript VSCode project

Project Intro

I am working on an electron project using VSCode

I installed electron using npm install electron

The electron.d.ts file was empty at the time so I just copied the electron typings file and pasted it there and after that, the electron intellisense was working fine.

Problem

I also wanted to add another typings file with some interface declarations for some of my custom JavaScript objects i.e.

declare namespace ProjectName {
    interface Item {
        property?: string;
        name: string;
    }
}

But I couldn't find a way to load my projectname.d.ts file to VSCode intellisense.

What I tried

I tried using typings install "projectname.d.ts" which created the typings folder, typings.json etc. This was only working after opening the typings file in VSCode then closing and reopening the app. That only worked while I kept the typings file open. This is not a very convenient way to add my interface declarations.

Since VSCode was loading the electron.d.ts file properly I thought of just adding my custom namespace at the bottom of that file. This 'hack' worked as expected but I don't think it is a proper way of solving this issue. Furthermore, since VSCode could read the electron typings file then it should be possible to load a new typings file.

About VSCode

Version: 1.17.0
Shell: 1.7.7
Node: 7.9.0
Architecture: x64



from Add custom typings file in a JavaScript VSCode project

No comments:

Post a Comment