尝试扩展接口时,历史记录未定义功能

时间:2019-06-23 00:08:37

标签: typescript react-router

我正在尝试使用支持搜索解析的方法来扩展反应路由器的历史记录。

我尝试将模块定义和扩展名移至单独的文件,以不同的名称导入历史记录,因为该名称与全局ts历史记录定义冲突。

import { History } from "history";

declare module "history" {
    interface History {
        test: () => void;
    }
}

export function test(this: History) {
    console.log(this);
}

// History here is refering to lib.d.ts history for some reason
History.prototype.test = test; // ERROR: test does not exitst on preprty of type History<any>

0 个答案:

没有答案