Flow.js映射不可写吗?

时间:2019-10-31 13:03:09

标签: javascript flowtype

/* @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]

您可以在这里尝试 https://flow.org/try/#0PQKgBAAgZgNg9gdzCYAoVMCmAXMBbALjAFkBDABwB4A7AVzwCNMAnAGjAGdtmBLagcwB8AbnR4wAXjDVMSMuQAUASlGo8AbQCMAXUlgA5AEcEmfcKA

1 个答案:

答案 0 :(得分:1)

该死,这是因为在带有地图的JS中,您不允许m[key] = value;m.set(key, value)