Angular2和TypeScript在VS2013中显示错误“无法找到名称'Map'

时间:2016-06-21 08:48:56

标签: visual-studio-2013 typescript angular

我正在尝试使用Visual Studio中的TypeScript构建Angular2应用程序。我按照angular2站点中“5分钟快速启动”中显示的步骤进行操作。(https://angular.io/guide/quickstart)。但是我得到了以下错误,如下图所示 enter image description here

任何人都可以帮我解决问题“无法找到名字'地图'吗?感谢先进 package.json文件定义如下

{
  "name": "angular2-quickstart",
  "version": "1.0.0",
  "scripts": {
    "start": "tsc && concurrently \"npm run tsc:w\" \"npm run lite\" ",
    "lite": "lite-server",
    "postinstall": "typings install",
    "tsc": "tsc",
    "tsc:w": "tsc -w",
    "typings": "typings"
  },
  "license": "ISC",
  "dependencies": {
    "@angular/common":  "2.0.0-rc.2",
    "@angular/compiler":  "2.0.0-rc.2",
    "@angular/core":  "2.0.0-rc.2",
    "@angular/http":  "2.0.0-rc.2",
    "@angular/platform-browser":  "2.0.0-rc.2",
    "@angular/platform-browser-dynamic":  "2.0.0-rc.2",
    "@angular/router":  "2.0.0-rc.2",
    "@angular/router-deprecated":  "2.0.0-rc.2",
    "@angular/upgrade":  "2.0.0-rc.2",
    "systemjs": "0.19.27",
    "core-js": "^2.4.0",
    "reflect-metadata": "^0.1.3",
    "rxjs": "5.0.0-beta.6",
    "zone.js": "^0.6.12",
    "angular2-in-memory-web-api": "0.0.12",
    "bootstrap": "^3.3.6"
  },
  "devDependencies": {
    "concurrently": "^2.0.0",
    "lite-server": "^2.2.0",
    "typescript": "^1.8.10",
    "typings":"^1.0.4"
  }
}

3 个答案:

答案 0 :(得分:3)

我必须更改VS文件,如 NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];

所述

Invalid module name in augmentation #8518

  

我现在看到了这个问题。这是#7415的副本,应该修复   在下一个版本中(见#7507)。

     

目前正在解决,您可以替换var obj = [{ 'itemz': 'tomato', 'value': 5 }, { 'itemz': 'potatos', 'value': 3 }, { 'itemz': 'banana', 'value': 7 }, { 'itemz': 'orange', 'value': 6 }, { 'itemz': 'apple', 'value': 4 }, { 'itemz': 'cherries', 'value': 5 }, { 'itemz': 'watermelon', 'value': 9 }, { 'itemz': 'orange', 'value': 8 }]; var res = obj.filter(function(d) { if (d.value == 9) { return d; } }); for (var i = 0; i < obj.length; i++) { for (var j = 0; j < obj.length; j++) { if (obj[i].value + obj[j].value == 9) { res.push(obj[i]); res.push(obj[j]); } } } function getUniqueElements(arr) { var obj = {}; var objArray = []; for (var i = 0; i < arr.length; i++) { obj[arr[i]['value']] = arr[i]; } for (var prop in obj) { objArray.push(obj[prop]); } return objArray; } var result = getUniqueElements(res); document.write('<pre>' + JSON.stringify(result, 0, 4) + '</pre>');   随着文件   https://raw.githubusercontent.com/Microsoft/TypeScript/Fix8518/lib/typescriptServices.js。   首先进行本地备份。

这与VS 2015有关,但下面某处也应该是VS 2013的一些解决方案

答案 1 :(得分:0)

在谷歌搜索后,我找到了解决方案,我想与大家分享 只需在组件.ts文件的顶部添加以下行

from time import time, ctime, sleep
from threading import Thread, Lock
from Queue import Queue

class MyQueue(object):
    def __init__(self):
        self.store = []

    def put(self, value):
        self.store.append(value)

    def get(self):
        return self.store.pop(0)

    def empty(self):
        return not self.store


class SyncQueue(Thread):
    __lock = Lock()

    def __init__(self, name, delay, queue):
        Thread.__init__(self)
        self.name = name
        self.delay = delay
        self.queue = queue

    def run(self):
        print "Starting %s" % self.name
        while not self.queue.empty():
            with self.__lock:
                print "%s got %s" % (
                        self.name,
                        self.queue.get())
            sleep(self.delay)
        while not job_done:
            sleep(self.delay)
        print "Exiting %s" % self.name

if __name__ == "__main__":
    job_done = False
    #q = Queue(5) # Python's Queue
    q = MyQueue() # Custom Queue
    for i in xrange(5):
        q.put(i)
    q1 = SyncQueue("Q1", .5, q)
    q2 = SyncQueue("Q2", 1, q)
    q1.start()
    q2.start()

    # Wait for the job to be done
    while not q.empty():
        pass
    job_done = True
    q1.join()
    q2.join()
    print "All done!"

看到下面的图片

enter image description here

<强>更新
如果您使用anguler2 beta(angular2 / core),那么您应该添加

///<reference path="../node_modules/angular2/typings/browser.d.ts"/>

但如果你使用angular2 rc1 / rc2 / rc3(@ angular2 / core),你应该添加

///<reference path="../node_modules/angular2/typings/browser.d.ts"/>

答案 2 :(得分:0)

要解决此问题,请打开您的typings.d.ts并注释以下行 注释掉下面的代码,它将解决您的问题。

//declare var module: {
//  id: string;
//};