2

我正在使用下面链接中的 history.js 声明文件。

History.js 声明文件

但是,“历史”对象与 lib.d.ts 中的本机历史对象冲突。有没有办法克服这个问题?我进行了三次检查,包括对 history.js 声明文件的引用。

4

2 回答 2

3

I have sent a pull request to the Definitely Typed project to change the definition file to this:

interface HistoryAdapter {
    bind(element, event, callback);
    trigger(element, event);
    onDomLoad(callback);
}

interface History {
    enabled: bool;
    pushState(data, title, url);
    replaceState(data, title, url);
    getState();
    getHash();
    Adapter: HistoryAdapter;
    back();
    forward();
    go(X);
    log(...messages: any[]);
    debug(...messages: any[]);
}

This gracefully adds the additional properties and methods to the existing interface and so on to the existing History class definition, so using:

var history = new History();

Should now work. Just grab the latest History definition from Definitely Typed.

Edit:

Github links have changed (yet again). File is now at: https://github.com/borisyankov/DefinitelyTyped/tree/master/history

于 2013-01-04T09:36:08.713 回答
1

当然,只需将您的对象转换为HistoryStaticDefinitelyTyped 提供的接口即可。

var h = new History();
h = <HistoryStatic>h;
h.getState();

如果声明文件扩展已经提供History的接口lib.d.ts而不是创建自己的接口会更好。或许是有意为之,或许是被忽视了。

于 2013-01-04T01:46:12.707 回答