How to override or extend a libary type definition in Typescript

Viewed 31236

If I import a library type declaration in Typescript. How can I extend the definition of that library when there's compiler issues with it, but it would be otherwise valid js code? For example validate.js type bindings are very inaccurate compared to the actual implementation. Something like shown below....

import * as validate from 'validate.js';

declare namespace validate {
  Promise: any;
  async: any;
}

Similarly with mongoose I can't access modelSchemas property but I need to.

import * as mongoose from 'mongoose';
declare namespace mongoose {
  export modelSchemas any[];
}

So if I want to add definitions to the existing types just to shut the compiler up. How can I do that?

1 Answers
Related