【问题标题】:History.js and TypeScript - Historyjs is not definedHistory.js 和 TypeScript - Historyjs 未定义
【发布时间】:2013-08-22 11:23:02
【问题描述】:

我正在尝试将 History.js (https://github.com/browserstate/history.js) 与 TypeScript 一起使用,使用 DefinitiveTyped 声明文件 (https://github.com/borisyankov/DefinitelyTyped/blob/master/history/history.d.ts)

Historyjs 对象是在 History.d.ts 中声明的,但是当我尝试使用 Historyjs 对象时,我收到一条错误消息“Historyjs 未定义”,我在 history.js 文件中进行了搜索,但找不到 javascript Historyjs 对象的声明 ...

发生了什么事?有任何想法吗?谢谢!!

【问题讨论】:

  • 。错误是运行时还是编译时?
  • 这是一个 javascrip 运行时错误。

标签: typescript history.js


【解决方案1】:

此问题记录在定义文件中。当您添加参考线时,

/// <reference path="history.d.ts"/> 

到文件的顶部,然后您必须像这样“导入”变量:

// var Historyjs: Historyjs = <any>History;

您可以在此处查看更多信息:https://github.com/borisyankov/DefinitelyTyped/issues/277

【讨论】:

    【解决方案2】:

    添加 TypeScript 定义文件不会导致 JavaScript 自动加载。您仍然需要手动将 history.js 加载到浏览器中。 PS:确保你加载history.js之前你的文件。

    【讨论】:

    • 确保在文件/// &lt;reference path="history.d.ts"/&gt;中添加参考history.d.ts
    • 是的,我有参考 history.d.ts
    【解决方案3】:

    阅读 https://github.com/browserstate/history.js/ 应该是 History 而不是 Historyjs

    【讨论】:

      猜你喜欢
      • 2018-06-18
      • 1970-01-01
      • 1970-01-01
      • 2020-03-27
      • 1970-01-01
      • 2017-12-29
      • 2016-12-14
      • 2021-06-14
      • 2017-09-14
      相关资源
      最近更新 更多