Typescript extend third-party declaration files

后端 未结 1 1968
[愿得一人]
[愿得一人] 2021-02-20 01:59

How can I extend third-party declaration files?
for example, I want to extend Context from @types/koa and add an extra field(resource) to it.

相关标签:
1条回答
  • 2021-02-20 02:57

    You have to use module augmentation as described here:

    import { Context } from "koa";
    
    declare module "koa" {
        interface Context {
            resource: any;
        }
    }
    
    0 讨论(0)
提交回复
热议问题