Extend interface defined in .d.ts file
// How to extend Validator interface adding isArray() method??
You cannot do this in a file that is a module (some guidance here) and your file is a module because you have import expressValidator
.
Instead create a extendedValidator.d.ts
and add the new stuff for TypeScript's engine:
declare module ExpressValidator {
export interface Validator {
isArray: any;
}
}
I was able to accomplish this by following the directions at https://www.credera.com/blog/technology-solutions/typescript-adding-custom-type-definitions-for-existing-libraries/. There they use the example of react
.
import 'react';
declare module 'react' {
interface OlHTMLAttributes<T> {
type?: "1" | "a" | "A" | "i" | "I";
}
}
I found this works really well for winston
too.