问题描述
^ 1.0.0-beta.11-webpack"现在将core-js用于polyfills.
^1.0.0-beta.11-webpack" now uses core-js for polyfills.
我正在尝试导入要在我的应用程序中使用的地图
I am trying to import a Map for use in my application
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文件
I have even added the core-js d.ts file using
npm install --save @types/core-js (typescript 2.0 is used)
但是,两个导入都不能解析Map符号.
yet neither of the imports resolves the Map symbol.
我想念什么?
我现在可以使用Map实体,但是即使可以设置/获取地图键/值,我在控制台中也会遇到很多错误
I can now use the Map entity, but I am getting a lot of errors in the cosole, even though I can set/get map keys/values
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
推荐答案
此处的问题是,core-js
的声明重新声明了TypeScript本身提供并默认包含的许多类型.
The issue here is that the declarations for core-js
redeclare many types that TypeScript itself provides and includes by default.
core-js
旨在多填充ECMAScript标准库的当前和将来规范. TypeScript旨在描述那些当前和将来的规范的类型.
core-js
aims to polyfill the current and future specifications of the ECMAScript standard library. TypeScript aims to describe the types of those same current and future specifications.
core-js
可用的类型声明因此与该语言提供的类型声明重叠.
The type declarations available for core-js
thusly overlap with those provided by the language.
您可以使用一些可靠的选择:
You have a few solid options that you can use:
- 在tsconfig.json中,在
"compilerOptions"
下指定"noLib": true
,以指示TypeScript避免在编译上下文中自动包括其内置的标准库声明. - 在tsconfig.json中指定
"lib"
选项,该选项可让您更精细地控制要包含的标准库声明.例如,您可以指定"lib": ["es2017.symbol.wellknown", "dom"]
. - 卸载@ types/core-js软件包,并通过指定
"lib": ["es2017", "dom"]
来简单地使用TypeScript的内置声明文件.您将继续使用core-js
,但是将使用TypeScript自己维护良好的定义来 type 实现.
- In tsconfig.json specify
"noLib": true
under"compilerOptions"
to instruct TypeScript to refrain from automatically including its built in standard library declarations in the compilation context. - In tsconfig.json specify the
"lib"
option which gives you more granular control over which standard library declarations are included. For example you might specify"lib": ["es2017.symbol.wellknown", "dom"]
. - Uninstall the @types/core-js package and simply use TypeScript's built in declaration files as above by specifying
"lib": ["es2017", "dom"]
. You will continue to usecore-js
, but you will be using TypeScript's own well-maintained definitions to type the implementation.
我花了一些时间在这些选项之间来回移动之后,发现选项3是最容易维护的.
After spending some time going back and forth between these options myself, I find that option 3 is the easiest to maintain.
请注意,TypeScript自动包含的声明文件取决于tsconfig中的"target"
属性.
Please note that the declaration files automatically included by TypeScript depend on the the "target"
property in tsconfig.
这篇关于如何将Core-JS Map导入angular-cli Webpack生成的应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!