Extend interface defined in .d.ts file

后端 未结 2 1911
逝去的感伤
逝去的感伤 2020-11-30 10:40

In my TypeScript project, I use DefinitelyTyped definitions for external js dependencies.

Sometimes it might happen that these definitions are outdated. It might als

相关标签:
2条回答
  • 2020-11-30 11:13

    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.

    0 讨论(0)
  • 2020-11-30 11:14

    // 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;
      }
    }
    
    0 讨论(0)
提交回复
热议问题