【问题标题】:Upgrading typings from 0.x to 1.x. Where is /typings?将类型从 0.x 升级到 1.x。 /类型在哪里?
【发布时间】:2016-06-16 01:04:01
【问题描述】:

在 TypeScript 中编写 Angular 2 应用程序时,我正在尝试遵循 5 Min Quickstart guide。最近 npm typings 包从 0.x 升级到 1.x。根据official instructions,我们应该在升级时删除/typings,这就是我所做的。删除该目录后,我运行npm uninstall typings,然后运行npm install typings。我现在安装了typings 1.1.0。

这是我的 typings.json

{
  "globalDependencies": {
    "core-js": "registry:dt/core-js#0.0.0+20160317120654",
    "jasmine": "registry:dt/jasmine#2.2.0+20160505161446",
    "node": "registry:dt/node#4.0.0+20160509154515"
  }
}

问题是,我希望安装创建一个新的/typings 并用new file structure 填充它。但是,我仍然没有/typings。尝试运行 typings install 会引发错误 'typings' is not a recognized command, program or batch file(我在 Windows 7 上)。什么给了?

为什么会出现问题:打字稿编译器会抛出很多 "Cannot find name 'Promise'" (or 'Set' or 'Map') 错误,除非我引用(现已删除)///<reference path="../typings/main/ambient/es6-shim/es6-shim.d.ts"/>

【问题讨论】:

    标签: angular npm typescript-typings


    【解决方案1】:

    typings install 不会被识别(可能是因为我没有全局安装它)。要创建和填充/typings,我需要执行npm run typings install。这创建了/typings/globals 并用我的typings.json 中的包填充它。

    为了处理“Cannot find name 'Promise'”错误,我将引导文件中的引用路径更改为

    老:///<reference path="../typings/main/ambient/es6-shim/es6-shim.d.ts"/>

    致新人:///<reference path="../typings/globals/core-js/index.d.ts"/>

    鉴于 Angular 2 最近在 typings.json 中将 es6-shim 替换为 core-js

    【讨论】:

      【解决方案2】:

      不久前我也遇到过这个问题。为了修复它,我添加了 ///<reference path="../../node_modules/angular2-in-memory-web-api/typings/browser.d.ts" /> tsd.d.ts 文件的此引用路径。路径可能会有所不同,具体取决于您的环境设置方式。但如果我没记错的话,browser.d.ts 有这些类型的参考。

      这是一个相关的问题预发布候选。 Angular 2 can't find Promise,Map,Set and Iterator

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-06-02
        • 2013-10-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-09-12
        • 1970-01-01
        相关资源
        最近更新 更多