首页 > 解决方案 > 如何在打字稿中向声明的类添加方法

问题描述

我正在尝试将自定义方法添加到由外部库导出的现有类中。此类定义如下:export declare class Site.

我尝试使用包名称声明一个模块,但是当我添加接口时,打字稿抱怨:'Site' only refers to a type, but is being used as a value here.ts(2693)

这是我试过的打字:

declare module '@pnp/sp' {
  interface Site {
    getChanges: (query: any) => Promise<any>;
  }
}

标签: typescript

解决方案


推荐阅读