nhjk
nhjk

Reputation: 7840

How do I extend a typings declaration?

I'm using an npm module that has declarations in the DefinitelyTyped/DefinitelyTyped github repo, but typings for the module are incomplete.

I have made a pull request to get the missing declarations in, however until its accepted I need to have a way to temporarily extend the incomplete declaration.

Ideally I would like to be able to have a temporaryTypings.d.ts file in my project root where I can add declarations for every situation like this that I run into.

Upvotes: 2

Views: 901

Answers (2)

Ivan Drinchev
Ivan Drinchev

Reputation: 19591

You can always have some project.d.ts file somewhere in your source file.

You can reference to it from some entry point like /// <reference path="path/to/project.d.ts" /> or from your tsconfig.json and just add the typings that are working for you there.

For example my global file usually consists :

declare module "leftpad" {
    var t : any;
    export = t;
}

Which helps me to import my modules without require. After the definition files are available, you can install them with npm install @types/leftpad --save-dev and then just remove that module declaration from your global.d.ts file.

Upvotes: 1

Jokester
Jokester

Reputation: 5617

You can install definitions from non-DefinitelyTyped source, like your fork of DT:

# (this example is taken from https://www.npmjs.com/package/typings )
# If you need a specific commit from github. 
$ typings install d3=github:DefinitelyTyped/DefinitelyTyped/d3/d3.d.ts#1c05872e7811235f43780b8b596bfd26fe8e7760

npm since typescript 2 can install module from specific git repo as well.

Upvotes: 1

Related Questions