角2打字稿找不到名称 [英] Angular 2 typescript can't find names
问题描述
我使用的角2打字稿1.6,当我编译code我得到这个错误:
错误TS2304:找不到名称'地图'。
node_modules / angular2 / src目录/核心/ change_detection /分析器/ locals.d.ts(4,42):错误TS2304:找不到名称'地图'。
node_modules / angular2 / src目录/核心/正面/ collection.d.ts(1,25):错误TS2304:找不到名称'MapConstructor。
node_modules / angular2 / src目录/核心/正面/ collection.d.ts(2,25):错误TS2304:找不到名称'SetConstructor。
node_modules / angular2 / src目录/核心/正面/ collection.d.ts(4,27):错误TS2304:找不到名称'地图'。
node_modules / angular2 / src目录/核心/正面/ collection.d.ts(4,39):错误TS2304:找不到名称'地图'。
node_modules / angular2 / src目录/核心/正面/ collection.d.ts(7,9):错误TS2304:找不到名称'地图'。
node_modules / angular2 / src目录/核心/正面/ collection.d.ts(8,30):错误TS2304:找不到名称'地图'。
node_modules / angular2 / src目录/核心/正面/ collection.d.ts(11,43):错误TS2304:找不到名称'地图'。
node_modules / angular2 / src目录/核心/正面/ collection.d.ts(12,27):错误TS2304:找不到名称'地图'。
node_modules / angular2 / src目录/核心/正面/ collection.d.ts(14,23):错误TS2304:找不到名称'地图'。
node_modules / angular2 / src目录/核心/正面/ collection.d.ts(15,25):错误TS2304:找不到名称'地图'。
node_modules / angular2 / src目录/核心/正面/ collection.d.ts(94,41):错误TS2304:找不到名称设置。
node_modules / angular2 / src目录/核心/正面/ collection.d.ts(95,22):错误TS2304:找不到名称设置。
node_modules / angular2 / src目录/核心/正面/ collection.d.ts(96,25):错误TS2304:找不到名称设置。
node_modules / angular2 / src目录/核心/正面/ lang.d.ts(1,22):错误TS2304:找不到名称'BrowserNodeGlobal。
node_modules / angular2 / src目录/核心/正面/ lang.d.ts(33,59):错误TS2304:找不到名称'地图'。
node_modules / angular2 / src目录/核心/正面/ promise.d.ts(1,10):错误TS2304:找不到名称承诺。
node_modules / angular2 / src目录/核心/正面/ promise.d.ts(3,14):错误TS2304:找不到名称承诺。
node_modules / angular2 / src目录/核心/正面/ promise.d.ts(8,32):错误TS2304:找不到名称承诺。
node_modules / angular2 / src目录/核心/正面/ promise.d.ts(9,38):错误TS2304:找不到名称承诺。
node_modules / angular2 / src目录/核心/正面/ promise.d.ts(10,35):错误TS2304:找不到名称承诺。
node_modules / angular2 / src目录/核心/正面/ promise.d.ts(10,93):错误TS2304:找不到名称承诺。
node_modules / angular2 / src目录/核心/正面/ promise.d.ts(11,34):错误TS2304:找不到名称承诺。
node_modules / angular2 / src目录/核心/正面/ promise.d.ts(12,32):错误TS2304:找不到名称承诺。
node_modules / angular2 / src目录/核心/正面/ promise.d.ts(12149):错误TS2304:找不到名称承诺。
node_modules / angular2 / src目录/核心/正面/ promise.d.ts(13,43):错误TS2304:找不到名称承诺。
node_modules / angular2 / src目录/核心/连接/ element_injector.d.ts(72,32):错误TS2304:找不到名称'地图'。
node_modules / angular2 / src目录/核心/连接/ element_injector.d.ts(74,17):错误TS2304:找不到名称'地图'。
node_modules / angular2 / src目录/核心/连接/ element_injector.d.ts(78184):错误TS2304:找不到名称'地图'。
node_modules / angular2 / src目录/核心/连接/ element_injector.d.ts(83182):错误TS2304:找不到名称'地图'。
node_modules / angular2 / src目录/核心/连接/ element_injector.d.ts(107,37):错误TS2304:找不到名称'地图'。
node_modules / angular2 / src目录/核心/连接/ proto_view_factory.d.ts(27146):错误TS2304:找不到名称'地图'。
node_modules / angular2 / src目录/核心/连接/ view.d.ts(52144):错误TS2304:找不到名称'地图'。
node_modules / angular2 / src目录/核心/连接/ view.d.ts(76,79):错误TS2304:找不到名称'地图'。
node_modules / angular2 / src目录/核心/连接/ view.d.ts(77,73):错误TS2304:找不到名称'地图'。
node_modules / angular2 / src目录/核心/连接/ view.d.ts(94,31):错误TS2304:找不到名称'地图'。
node_modules / angular2 / src目录/核心/连接/ view.d.ts(97,18):错误TS2304:找不到名称'地图'。
node_modules / angular2 / src目录/核心/连接/ view.d.ts(100,24):错误TS2304:找不到名称'地图'。
node_modules / angular2 / src目录/核心/连接/ view.d.ts(103142):错误TS2304:找不到名称'地图'。
node_modules / angular2 / src目录/核心/连接/ view.d.ts(104160):错误TS2304:找不到名称'地图'。
node_modules / angular2 / src目录/核心/渲染/ api.d.ts(281,74):错误TS2304:找不到名称'地图'。
node_modules / angular2 / src目录/核心/区/ ng_zone.d.ts(1,37):错误TS2304:找不到名称区域。
这是code:
进口'反映的元数据';
进口{引导,色差,CORE_DIRECTIVES,FORM_DIRECTIVES}从'angular2 /核心;
@零件({
选择:我的应用,
模板:'<输入类型=文本[(NG-模式)] =标题/>< H1>的{{title}}< / H1>,
指令:[CORE_DIRECTIVES]
})
类AppComponent {
标题:字符串; 构造函数(){
this.title ='你好角2';
}
}
引导(AppComponent);
一个已知问题:<一href=\"https://github.com/angular/angular/issues/4902\">https://github.com/angular/angular/issues/4902
核心原因是: .d.ts
文件隐含打字稿包含编译目标各不相同,所以人们需要有更多的环境目标的声明时, ES5
即使事情实际上是美元的运行时间p $ psent(如铬)。更多关于<一个href=\"https://basarat.gitbooks.io/typescript/content/docs/types/lib.d.ts.html\"><$c$c>lib.d.ts$c$c>
I am using angular 2 with typescript 1.6 and when i compile the code i get this errors:
Error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/core/change_detection/parser/locals.d.ts(4,42): Error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/core/facade/collection.d.ts(1,25): Error TS2304: Cannot find name 'MapConstructor'.
node_modules/angular2/src/core/facade/collection.d.ts(2,25): Error TS2304: Cannot find name 'SetConstructor'.
node_modules/angular2/src/core/facade/collection.d.ts(4,27): Error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/core/facade/collection.d.ts(4,39): Error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/core/facade/collection.d.ts(7,9): Error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/core/facade/collection.d.ts(8,30): Error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/core/facade/collection.d.ts(11,43): Error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/core/facade/collection.d.ts(12,27): Error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/core/facade/collection.d.ts(14,23): Error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/core/facade/collection.d.ts(15,25): Error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/core/facade/collection.d.ts(94,41): Error TS2304: Cannot find name 'Set'.
node_modules/angular2/src/core/facade/collection.d.ts(95,22): Error TS2304: Cannot find name 'Set'.
node_modules/angular2/src/core/facade/collection.d.ts(96,25): Error TS2304: Cannot find name 'Set'.
node_modules/angular2/src/core/facade/lang.d.ts(1,22): Error TS2304: Cannot find name 'BrowserNodeGlobal'.
node_modules/angular2/src/core/facade/lang.d.ts(33,59): Error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/core/facade/promise.d.ts(1,10): Error TS2304: Cannot find name 'Promise'.
node_modules/angular2/src/core/facade/promise.d.ts(3,14): Error TS2304: Cannot find name 'Promise'.
node_modules/angular2/src/core/facade/promise.d.ts(8,32): Error TS2304: Cannot find name 'Promise'.
node_modules/angular2/src/core/facade/promise.d.ts(9,38): Error TS2304: Cannot find name 'Promise'.
node_modules/angular2/src/core/facade/promise.d.ts(10,35): Error TS2304: Cannot find name 'Promise'.
node_modules/angular2/src/core/facade/promise.d.ts(10,93): Error TS2304: Cannot find name 'Promise'.
node_modules/angular2/src/core/facade/promise.d.ts(11,34): Error TS2304: Cannot find name 'Promise'.
node_modules/angular2/src/core/facade/promise.d.ts(12,32): Error TS2304: Cannot find name 'Promise'.
node_modules/angular2/src/core/facade/promise.d.ts(12,149): Error TS2304: Cannot find name 'Promise'.
node_modules/angular2/src/core/facade/promise.d.ts(13,43): Error TS2304: Cannot find name 'Promise'.
node_modules/angular2/src/core/linker/element_injector.d.ts(72,32): Error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/core/linker/element_injector.d.ts(74,17): Error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/core/linker/element_injector.d.ts(78,184): Error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/core/linker/element_injector.d.ts(83,182): Error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/core/linker/element_injector.d.ts(107,37): Error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/core/linker/proto_view_factory.d.ts(27,146): Error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/core/linker/view.d.ts(52,144): Error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/core/linker/view.d.ts(76,79): Error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/core/linker/view.d.ts(77,73): Error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/core/linker/view.d.ts(94,31): Error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/core/linker/view.d.ts(97,18): Error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/core/linker/view.d.ts(100,24): Error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/core/linker/view.d.ts(103,142): Error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/core/linker/view.d.ts(104,160): Error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/core/render/api.d.ts(281,74): Error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/core/zone/ng_zone.d.ts(1,37): Error TS2304: Cannot find name 'Zone'.
This is the code:
import 'reflect-metadata';
import {bootstrap, Component, CORE_DIRECTIVES, FORM_DIRECTIVES} from 'angular2/core';
@Component({
selector: 'my-app',
template: '<input type="text" [(ng-model)]="title" /><h1>{{title}}</h1>',
directives: [ CORE_DIRECTIVES ]
})
class AppComponent {
title :string;
constructor() {
this.title = 'hello angular 2';
}
}
bootstrap(AppComponent);
A known issue: https://github.com/angular/angular/issues/4902
Core reason: the .d.ts
file implicitly included by TypeScript varies with the compile target, so one needs to have more ambient declarations when targeting es5
even if things are actually present in the runtimes (e.g. chrome). More on lib.d.ts
这篇关于角2打字稿找不到名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!