typescript - 如何在打字稿中向声明的类添加方法
问题描述
我正在尝试将自定义方法添加到由外部库导出的现有类中。此类定义如下: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>;
}
}
解决方案
推荐阅读
- sql - 我的 SQL 查询中 v 附近或 v 处的语法错误,但它不起作用
- kotlin - 使用类似于来自 RxJava 的 `PublishSubject.onError` 的共享流向下游传播异常
- html - Jekyll 将包含文件中的自定义变量视为文件名
- python - 不知道使用 T2T 时要设置哪些目录
- post - Post Widget elementor Pro 上的巨大空间。请看图片
- android - kotlin android rooom 如何从带有编辑文本的列中计算数据?
- batch-file - 尝试禁用在 AD 中处于非活动状态超过 X 时间的用户
- python - Python pip - 从本地目录安装特定的包版本
- socket.io - 向房间内命名空间中的所有套接字发送事件,发送者除外
- python - 如何查找 id 具有前缀“Translations_”的元素?