d-_-b
d-_-b

Reputation: 23201

How to overwrite DefinitelyTyped or reference a custom file

I'm using a Node library (https://github.com/lbdremy/solr-node-client) and when using VSCode, it automagically pulls in a community-written Type definition (https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/solr-client).

My problem is that this is missing methods, or I prefer to have some methods return a more precise Type (specific my project).

For my own code, I can use

/** 
 * @typedef {Number} CustomType
 */

Question

How can I create a separate file and add/modify the types of an existing definition.

Upvotes: 0

Views: 292

Answers (1)

Donovan Hiland
Donovan Hiland

Reputation: 1499

Depending on how the types were declared (either a namespace or module) you can create a type definition file *.d.ts and add your declarations there to be merged.

An example I have for jest matchers:

declare namespace jest {
  interface Matchers<R> {
    toHave(expected: string): R
  }
}

Make sure your definition files are included in the files your tsconfig is looking at.

https://www.typescriptlang.org/docs/handbook/declaration-merging.html

Upvotes: 1

Related Questions