Sta*_*min 3 javascript typescript ecmascript-6
我有一个键和值作为字符串的映射。但是,当尝试根据键检索值时,它会抛出错误。
以下是我的代码片段。
let map:Map<string, string> = { [ "key1": "hello world 1" ], ["key2": "hello world 2"] } ;
alert( JSON.stringify(map.get("key")) );
Run Code Online (Sandbox Code Playgroud)
我在下面得到的例外如下。
VM133:4 Uncaught TypeError: map.get is not a function
at eval (eval at exec (typescript.js:41), <anonymous>:4:26)
at exec (typescript.js:41)
at HTMLDocument.runScripts (typescript.js:41)
Run Code Online (Sandbox Code Playgroud)
如果你能告诉我我做错了什么,不胜感激
谢谢你
AMap不是原始类型,需要使用构造函数调用(我认为 Typescript 应该对此发出警告)。
你可能正在寻找这个:
const map:Map<string, string> = new Map([
[ "key1", "hello world 1" ],
[ "key2", "hello world 2" ],
])
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3430 次 |
| 最近记录: |