如何将core-js Map导入angular-cli webpack生成的应用程序

时间:2016-08-07 12:18:18

标签: angular webpack angular2-forms angular-cli typescript2.0

^ 1.0.0-beta.11-的WebPack"现在使用core-js进行polyfills。

我正在尝试导入Map以在我的应用程序中使用

import {Map} from 'core-js/es6/map'
//import {Map} from 'core-js/library/es6/map'

export function updatePayload(data: any, isDataValid: boolean): Map<string, any> {
  const payload: Map<string, any> = new Map<string, any>()
  payload.set('data', data)
  payload.set('isDataValid', isDataValid)
  return payload
}

我甚至使用

添加了core-js d.ts文件
npm install --save @types/core-js (typescript 2.0 is used)

然而这两个导入都没有解析Map符号。

我错过了什么?

编辑1 |生成错误

我现在可以使用Map实体,但是我在cosole中遇到很多错误,即使我可以设置/获取地图键/值

client:49 [default] J:\workspace\angular2\ts\epimss\node_modules\@types\core-js\index.d.ts:21:13 
Duplicate identifier 'PropertyKey'.errors @ client:49sock.onmessage @ client:83EventTarget.dispatchEvent @ eventtarget.js:51(anonymous function) @ main.js:274SockJS._transportMessage @ main.js:272EventEmitter.emit @ emitter.js:50WebSocketTransport.ws.onmessage @ websocket.js:35wrapFn @ zone.js:769ZoneDelegate.invokeTask @ zone.js:356Zone.runTask @ zone.js:256ZoneTask.invoke @ zone.js:423
client:49 [default] J:\workspace\angular2\ts\epimss\node_modules\@types\core-js\index.d.ts:58:4 
All declarations of 'name' must have identical modifiers.errors @ client:49sock.onmessage @ client:83EventTarget.dispatchEvent @ eventtarget.js:51(anonymous function) @ main.js:274SockJS._transportMessage @ main.js:272EventEmitter.emit @ emitter.js:50WebSocketTransport.ws.onmessage @ websocket.js:35wrapFn @ zone.js:769ZoneDelegate.invokeTask @ zone.js:356Zone.runTask @ zone.js:256ZoneTask.invoke @ zone.js:423
client:49 [default] J:\workspace\angular2\ts\epimss\node_modules\@types\core-js\index.d.ts:118:4 
Subsequent variable declarations must have the same type.  Variable '[Symbol.unscopables]' must be of type '{ copyWithin: boolean; entries: boolean; fill: boolean; find: boolean; findIndex: boolean; keys: ...', but here has type 'any'.errors @ client:49sock.onmessage @ client:83EventTarget.dispatchEvent @ eventtarget.js:51(anonymous function) @ main.js:274SockJS._transportMessage @ main.js:272EventEmitter.emit @ emitter.js:50WebSocketTransport.ws.onmessage @ websocket.js:35wrapFn @ zone.js:769ZoneDelegate.invokeTask @ zone.js:356Zone.runTask @ zone.js:256ZoneTask.invoke @ zone.js:423
client:49 [default] J:\workspace\angular2\ts\epimss\node_modules\@types\core-js\index.d.ts:235:4 
All declarations of 'flags' must have identical modifiers.errors @ client:49sock.onmessage @ client:83EventTarget.dispatchEvent @ eventtarget.js:51(anonymous function) @ main.js:274SockJS._transportMessage @ main.js:272EventEmitter.emit @ emitter.js:50WebSocketTransport.ws.onmessage @ websocket.js:35wrapFn @ zone.js:769ZoneDelegate.invokeTask @ zone.js:356Zone.runTask @ zone.js:256ZoneTask.invoke @ zone.js:423
client:49 [default] J:\workspace\angular2\ts\epimss\node_modules\@types\core-js\index.d.ts:249:4 
All declarations of 'EPSILON' must have identical modifiers.errors @ client:49sock.onmessage @ client:83EventTarget.dispatchEvent @ eventtarget.js:51(anonymous function) @ main.js:274SockJS._transportMessage @ main.js:272EventEmitter.emit @ emitter.js:50WebSocketTransport.ws.onmessage @ websocket.js:35wrapFn @ zone.js:769ZoneDelegate.invokeTask @ zone.js:356Zone.runTask @ zone.js:256ZoneTask.invoke @ zone.js:423
client:49 [default] J:\workspace\angular2\ts\epimss\node_modules\@types\core-js\index.d.ts:284:4 
All declarations of 'MAX_SAFE_INTEGER' must have identical modifiers.errors @ client:49sock.onmessage @ client:83EventTarget.dispatchEvent @ eventtarget.js:51(anonymous function) @ main.js:274SockJS._transportMessage @ main.js:272EventEmitter.emit @ emitter.js:50WebSocketTransport.ws.onmessage @ websocket.js:35wrapFn @ zone.js:769ZoneDelegate.invokeTask @ zone.js:356Zone.runTask @ zone.js:256ZoneTask.invoke @ zone.js:423
client:49 [default] J:\workspace\angular2\ts\epimss\node_modules\@types\core-js\index.d.ts:291:4 
All declarations of 'MIN_SAFE_INTEGER' must have identical modifiers.errors @ client:49sock.onmessage @ client:83EventTarget.dispatchEvent @ eventtarget.js:51(anonymous function) @ main.js:274SockJS._transportMessage @ main.js:272EventEmitter.emit @ emitter.js:50WebSocketTransport.ws.onmessage @ websocket.js:35wrapFn @ zone.js:769ZoneDelegate.invokeTask @ zone.js:356Zone.runTask @ zone.js:256ZoneTask.invoke @ zone.js:423
client:49 [default] J:\workspace\angular2\ts\epimss\node_modules\@types\core-js\index.d.ts:430:4 
Subsequent variable declarations must have the same type.  Variable '[Symbol.toStringTag]' must be of type '"Symbol"', but here has type 'string'.errors @ client:49sock.onmessage @ client:83EventTarget.dispatchEvent @ eventtarget.js:51(anonymous function) @ main.js:274SockJS._transportMessage @ main.js:272EventEmitter.emit @ emitter.js:50WebSocketTransport.ws.onmessage @ websocket.js:35wrapFn @ zone.js:769ZoneDelegate.invokeTask @ zone.js:356Zone.runTask @ zone.js:256ZoneTask.invoke @ zone.js:423
client:49 [default] J:\workspace\angular2\ts\epimss\node_modules\@types\core-js\index.d.ts:430:4 
All declarations of '[Symbol.toStringTag]' must have identical modifiers.errors @ client:49sock.onmessage @ client:83EventTarget.dispatchEvent @ eventtarget.js:51(anonymous function) @ main.js:274SockJS._transportMessage @ main.js:272EventEmitter.emit @ emitter.js:50WebSocketTransport.ws.onmessage @ websocket.js:35wrapFn @ zone.js:769ZoneDelegate.invokeTask @ zone.js:356Zone.runTask @ zone.js:256ZoneTask.invoke @ zone.js:423
client:49 [default] J:\workspace\angular2\ts\epimss\node_modules\@types\core-js\index.d.ts:437:4 
All declarations of 'prototype' must have identical modifiers.errors @ client:49sock.onmessage @ client:83EventTarget.dispatchEvent @ eventtarget.js:51(anonymous function) @ main.js:274SockJS._transportMessage @ main.js:272EventEmitter.emit @ emitter.js:50WebSocketTransport.ws.onmessage @ websocket.js:35wrapFn @ zone.js:769ZoneDelegate.invokeTask @ zone.js:356Zone.runTask @ zone.js:256ZoneTask.invoke @ zone.js:423
client:49 [default] J:\workspace\angular2\ts\epimss\node_modules\@types\core-js\index.d.ts:465:4 
All declarations of 'hasInstance' must have identical modifiers.errors @ client:49sock.onmessage @ client:83EventTarget.dispatchEvent @ eventtarget.js:51(anonymous function) @ main.js:274SockJS._transportMessage @ main.js:272EventEmitter.emit @ emitter.js:50WebSocketTransport.ws.onmessage @ websocket.js:35wrapFn @ zone.js:769ZoneDelegate.invokeTask @ zone.js:356Zone.runTask @ zone.js:256ZoneTask.invoke @ zone.js:423
client:49 [default] J:\workspace\angular2\ts\epimss\node_modules\@types\core-js\index.d.ts:471:4 
All declarations of 'isConcatSpreadable' must have identical modifiers.errors @ client:49sock.onmessage @ client:83EventTarget.dispatchEvent @ eventtarget.js:51(anonymous function) @ main.js:274SockJS._transportMessage @ main.js:272EventEmitter.emit @ emitter.js:50WebSocketTransport.ws.onmessage @ websocket.js:35wrapFn @ zone.js:769ZoneDelegate.invokeTask @ zone.js:356Zone.runTask @ zone.js:256ZoneTask.invoke @ zone.js:423
client:49 [default] J:\workspace\angular2\ts\epimss\node_modules\@types\core-js\index.d.ts:477:4 
All declarations of 'iterator' must have identical modifiers.errors @ client:49sock.onmessage @ client:83EventTarget.dispatchEvent @ eventtarget.js:51(anonymous function) @ main.js:274SockJS._transportMessage @ main.js:272EventEmitter.emit @ emitter.js:50WebSocketTransport.ws.onmessage @ websocket.js:35wrapFn @ zone.js:769ZoneDelegate.invokeTask @ zone.js:356Zone.runTask @ zone.js:256ZoneTask.invoke @ zone.js:423
client:49 [default] J:\workspace\angular2\ts\epimss\node_modules\@types\core-js\index.d.ts:483:4 
All declarations of 'match' must have identical modifiers.errors @ client:49sock.onmessage @ client:83EventTarget.dispatchEvent @ eventtarget.js:51(anonymous function) @ main.js:274SockJS._transportMessage @ main.js:272EventEmitter.emit @ emitter.js:50WebSocketTransport.ws.onmessage @ websocket.js:35wrapFn @ zone.js:769ZoneDelegate.invokeTask @ zone.js:356Zone.runTask @ zone.js:256ZoneTask.invoke @ zone.js:423
client:49 [default] J:\workspace\angular2\ts\epimss\node_modules\@types\core-js\index.d.ts:489:4 
All declarations of 'replace' must have identical modifiers.errors @ client:49sock.onmessage @ client:83EventTarget.dispatchEvent @ eventtarget.js:51(anonymous function) @ main.js:274SockJS._transportMessage @ main.js:272EventEmitter.emit @ emitter.js:50WebSocketTransport.ws.onmessage @ websocket.js:35wrapFn @ zone.js:769ZoneDelegate.invokeTask @ zone.js:356Zone.runTask @ zone.js:256ZoneTask.invoke @ zone.js:423
client:49 [default] J:\workspace\angular2\ts\epimss\node_modules\@types\core-js\index.d.ts:495:4 
All declarations of 'search' must have identical modifiers.errors @ client:49sock.onmessage @ client:83EventTarget.dispatchEvent @ eventtarget.js:51(anonymous function) @ main.js:274SockJS._transportMessage @ main.js:272EventEmitter.emit @ emitter.js:50WebSocketTransport.ws.onmessage @ websocket.js:35wrapFn @ zone.js:769ZoneDelegate.invokeTask @ zone.js:356Zone.runTask @ zone.js:256ZoneTask.invoke @ zone.js:423
client:49 [default] J:\workspace\angular2\ts\epimss\node_modules\@types\core-js\index.d.ts:501:4 
All declarations of 'species' must have identical modifiers.errors @ client:49sock.onmessage @ client:83EventTarget.dispatchEvent @ eventtarget.js:51(anonymous function) @ main.js:274SockJS._transportMessage @ main.js:272EventEmitter.emit @ emitter.js:50WebSocketTransport.ws.onmessage @ websocket.js:35wrapFn @ zone.js:769ZoneDelegate.invokeTask @ zone.js:356Zone.runTask @ zone.js:256ZoneTask.invoke @ zone.js:423
client:49 [default] J:\workspace\angular2\ts\epimss\node_modules\@types\core-js\index.d.ts:507:4 
All declarations of 'split' must have identical modifiers.errors @ client:49sock.onmessage @ client:83EventTarget.dispatchEvent @ eventtarget.js:51(anonymous function) @ main.js:274SockJS._transportMessage @ main.js:272EventEmitter.emit @ emitter.js:50WebSocketTransport.ws.onmessage @ websocket.js:35wrapFn @ zone.js:769ZoneDelegate.invokeTask @ zone.js:356Zone.runTask @ zone.js:256ZoneTask.invoke @ zone.js:423
client:49 [default] J:\workspace\angular2\ts\epimss\node_modules\@types\core-js\index.d.ts:513:4 
All declarations of 'toPrimitive' must have identical modifiers.errors @ client:49sock.onmessage @ client:83EventTarget.dispatchEvent @ eventtarget.js:51(anonymous function) @ main.js:274SockJS._transportMessage @ main.js:272EventEmitter.emit @ emitter.js:50WebSocketTransport.ws.onmessage @ websocket.js:35wrapFn @ zone.js:769ZoneDelegate.invokeTask @ zone.js:356Zone.runTask @ zone.js:256ZoneTask.invoke @ zone.js:423
client:49 [default] J:\workspace\angular2\ts\epimss\node_modules\@types\core-js\index.d.ts:519:4 
All declarations of 'toStringTag' must have identical modifiers.errors @ client:49sock.onmessage @ client:83EventTarget.dispatchEvent @ eventtarget.js:51(anonymous function) @ main.js:274SockJS._transportMessage @ main.js:272EventEmitter.emit @ emitter.js:50WebSocketTransport.ws.onmessage @ websocket.js:35wrapFn @ zone.js:769ZoneDelegate.invokeTask @ zone.js:356Zone.runTask @ zone.js:256ZoneTask.invoke @ zone.js:423
client:49 [default] J:\workspace\angular2\ts\epimss\node_modules\@types\core-js\index.d.ts:525:4 
All declarations of 'unscopables' must have identical modifiers.errors @ client:49sock.onmessage @ client:83EventTarget.dispatchEvent @ eventtarget.js:51(anonymous function) @ main.js:274SockJS._transportMessage @ main.js:272EventEmitter.emit @ emitter.js:50WebSocketTransport.ws.onmessage @ websocket.js:35wrapFn @ zone.js:769ZoneDelegate.invokeTask @ zone.js:356Zone.runTask @ zone.js:256ZoneTask.invoke @ zone.js:423
client:49 [default] J:\workspace\angular2\ts\epimss\node_modules\@types\core-js\index.d.ts:582:4 
Subsequent variable declarations must have the same type.  Variable '[Symbol.toStringTag]' must be of type '"Math"', but here has type 'string'.errors @ client:49sock.onmessage @ client:83EventTarget.dispatchEvent @ eventtarget.js:51(anonymous function) @ main.js:274SockJS._transportMessage @ main.js:272EventEmitter.emit @ emitter.js:50WebSocketTransport.ws.onmessage @ websocket.js:35wrapFn @ zone.js:769ZoneDelegate.invokeTask @ zone.js:356Zone.runTask @ zone.js:256ZoneTask.invoke @ zone.js:423
client:49 [default] J:\workspace\angular2\ts\epimss\node_modules\@types\core-js\index.d.ts:582:4 
All declarations of '[Symbol.toStringTag]' must have identical modifiers.errors @ client:49sock.onmessage @ client:83EventTarget.dispatchEvent @ eventtarget.js:51(anonymous function) @ main.js:274SockJS._transportMessage @ main.js:272EventEmitter.emit @ emitter.js:50WebSocketTransport.ws.onmessage @ websocket.js:35wrapFn @ zone.js:769ZoneDelegate.invokeTask @ zone.js:356Zone.runTask @ zone.js:256ZoneTask.invoke @ zone.js:423
client:49 [default] J:\workspace\angular2\ts\epimss\node_modules\@types\core-js\index.d.ts:586:4 
Subsequent variable declarations must have the same type.  Variable '[Symbol.toStringTag]' must be of type '"JSON"', but here has type 'string'.errors @ client:49sock.onmessage @ client:83EventTarget.dispatchEvent @ eventtarget.js:51(anonymous function) @ main.js:274SockJS._transportMessage @ main.js:272EventEmitter.emit @ emitter.js:50WebSocketTransport.ws.onmessage @ websocket.js:35wrapFn @ zone.js:769ZoneDelegate.invokeTask @ zone.js:356Zone.runTask @ zone.js:256ZoneTask.invoke @ zone.js:423
client:49 [default] J:\workspace\angular2\ts\epimss\node_modules\@types\core-js\index.d.ts:586:4 
All declarations of '[Symbol.toStringTag]' must have identical modifiers.errors @ client:49sock.onmessage @ client:83EventTarget.dispatchEvent @ eventtarget.js:51(anonymous function) @ main.js:274SockJS._transportMessage @ main.js:272EventEmitter.emit @ emitter.js:50WebSocketTransport.ws.onmessage @ websocket.js:35wrapFn @ zone.js:769ZoneDelegate.invokeTask @ zone.js:356Zone.runTask @ zone.js:256ZoneTask.invoke @ zone.js:423
client:49 [default] J:\workspace\angular2\ts\epimss\node_modules\@types\core-js\index.d.ts:601:4 
All declarations of 'size' must have identical modifiers.errors @ client:49sock.onmessage @ client:83EventTarget.dispatchEvent @ eventtarget.js:51(anonymous function) @ main.js:274SockJS._transportMessage @ main.js:272EventEmitter.emit @ emitter.js:50WebSocketTransport.ws.onmessage @ websocket.js:35wrapFn @ zone.js:769ZoneDelegate.invokeTask @ zone.js:356Zone.runTask @ zone.js:256ZoneTask.invoke @ zone.js:423
client:49 [default] J:\workspace\angular2\ts\epimss\node_modules\@types\core-js\index.d.ts:607:4 
All declarations of 'prototype' must have identical modifiers.errors @ client:49sock.onmessage @ client:83EventTarget.dispatchEvent @ eventtarget.js:51(anonymous function) @ main.js:274SockJS._transportMessage @ main.js:272EventEmitter.emit @ emitter.js:50WebSocketTransport.ws.onmessage @ websocket.js:35wrapFn @ zone.js:769ZoneDelegate.invokeTask @ zone.js:356Zone.runTask @ zone.js:256ZoneTask.invoke @ zone.js:423
client:49 [default] J:\workspace\angular2\ts\epimss\node_modules\@types\core-js\index.d.ts:618:4 
All declarations of 'size' must have identical modifiers.errors @ client:49sock.onmessage @ client:83EventTarget.dispatchEvent @ eventtarget.js:51(anonymous function) @ main.js:274SockJS._transportMessage @ main.js:272EventEmitter.emit @ emitter.js:50WebSocketTransport.ws.onmessage @ websocket.js:35wrapFn @ zone.js:769ZoneDelegate.invokeTask @ zone.js:356Zone.runTask @ zone.js:256ZoneTask.invoke @ zone.js:423
client:49 [default] J:\workspace\angular2\ts\epimss\node_modules\@types\core-js\index.d.ts:624:4 
All declarations of 'prototype' must have identical modifiers.errors @ client:49sock.onmessage @ client:83EventTarget.dispatchEvent @ eventtarget.js:51(anonymous function) @ main.js:274SockJS._transportMessage @ main.js:272EventEmitter.emit @ emitter.js:50WebSocketTransport.ws.onmessage @ websocket.js:35wrapFn @ zone.js:769ZoneDelegate.invokeTask @ zone.js:356Zone.runTask @ zone.js:256ZoneTask.invoke @ zone.js:423
client:49 [default] J:\workspace\angular2\ts\epimss\node_modules\@types\core-js\index.d.ts:639:4 
All declarations of 'prototype' must have identical modifiers.errors @ client:49sock.onmessage @ client:83EventTarget.dispatchEvent @ eventtarget.js:51(anonymous function) @ main.js:274SockJS._transportMessage @ main.js:272EventEmitter.emit @ emitter.js:50WebSocketTransport.ws.onmessage @ websocket.js:35wrapFn @ zone.js:769ZoneDelegate.invokeTask @ zone.js:356Zone.runTask @ zone.js:256ZoneTask.invoke @ zone.js:423
client:49 [default] J:\workspace\angular2\ts\epimss\node_modules\@types\core-js\index.d.ts:653:4 
All declarations of 'prototype' must have identical modifiers.errors @ client:49sock.onmessage @ client:83EventTarget.dispatchEvent @ eventtarget.js:51(anonymous function) @ main.js:274SockJS._transportMessage @ main.js:272EventEmitter.emit @ emitter.js:50WebSocketTransport.ws.onmessage @ websocket.js:35wrapFn @ zone.js:769ZoneDelegate.invokeTask @ zone.js:356Zone.runTask @ zone.js:256ZoneTask.invoke @ zone.js:423
client:49 [default] J:\workspace\angular2\ts\epimss\node_modules\@types\core-js\index.d.ts:665:4 
All declarations of 'value' must have identical modifiers.errors @ client:49sock.onmessage @ client:83EventTarget.dispatchEvent @ eventtarget.js:51(anonymous function) @ main.js:274SockJS._transportMessage @ main.js:272EventEmitter.emit @ emitter.js:50WebSocketTransport.ws.onmessage @ websocket.js:35wrapFn @ zone.js:769ZoneDelegate.invokeTask @ zone.js:356Zone.runTask @ zone.js:256ZoneTask.invoke @ zone.js:423
client:49 [default] J:\workspace\angular2\ts\epimss\node_modules\@types\core-js\index.d.ts:777:4 
All declarations of 'prototype' must have identical modifiers.errors @ client:49sock.onmessage @ client:83EventTarget.dispatchEvent @ eventtarget.js:51(anonymous function) @ main.js:274SockJS._transportMessage @ main.js:272EventEmitter.emit @ emitter.js:50WebSocketTransport.ws.onmessage @ websocket.js:35wrapFn @ zone.js:769ZoneDelegate.invokeTask @ zone.js:356Zone.runTask @ zone.js:256ZoneTask.invoke @ zone.js:423
client:49 [default] J:\workspace\angular2\ts\epimss\node_modules\typescript\lib\lib.es2015.core.d.ts:17:13 
Duplicate identifier 'PropertyKey'.errors @ client:49sock.onmessage @ client:83EventTarget.dispatchEvent @ eventtarget.js:51(anonymous function) @ main.js:274SockJS._transportMessage @ main.js:272EventEmitter.emit @ emitter.js:50WebSocketTransport.ws.onmessage @ websocket.js:35wrapFn @ zone.js:769ZoneDelegate.invokeTask @ zone.js:356Zone.runTask @ zone.js:256ZoneTask.invoke @ zone.js:423

1 个答案:

答案 0 :(得分:4)

这里的问题是core-js的声明重新声明了TypeScript本身提供的许多类型并默认包含。

core-js旨在填充ECMAScript标准库的当前和未来规范。 TypeScript旨在描述那些相同的当前和未来规范的类型。

core-js可用的类型声明因此与语言提供的声明重叠。

您可以使用几个可靠的选项:

  1. 在tsconfig.json中,在"noLib": true下指定"compilerOptions",以指示TypeScript避免在编译上下文中自动包含其内置的标准库声明。
  2. 在tsconfig.json中指定"lib"选项,它可以更精细地控制包含哪些标准库声明。例如,您可以指定"lib": ["es2017.symbol.wellknown", "dom"]
  3. 卸载@ types / core-js包,并通过指定"lib": ["es2017", "dom"]简单地使用TypeScript的内置声明文件。您将继续使用core-js,但您将使用TypeScript自己维护良好的定义来输入实现。
  4. 在我自己花了一些时间在这些选项之间来回转换之后,我发现选项3是最容易维护的。

    请注意,TypeScript自动包含的声明文件取决于tsconfig中的"target"属性。