/* @flow */
let m: Map<number, string>;
m = new Map();
m[1] = 'qwe';
给出此错误:
7: m[1] = 'qwe';
^ Cannot assign `'qwe'` to `m[1]` because an index signature declaring the expected key / value type is not writable.
7: m[1] = 'qwe';
^ Cannot assign `'qwe'` to `m[1]` because number [1] is incompatible with `$SymbolToStringTag` [2].
References:
7: m[1] = 'qwe';
^ [1]
[LIB] ..//static/v0.111.0/flowlib/core.js:606: +[key: $SymbolToStringTag]: any;
^ [2]
答案 0 :(得分:1)
该死,这是因为在带有地图的JS中,您不允许m[key] = value;
仅m.set(key, value)
。