|
38 | 38 | initializer at `let`.
|
39 | 39 | * [[link](#immutable-provide-type)] Always provide a type when
|
40 | 40 | writing an empty `Immutable` value.
|
| 41 | + * [[link](#immutable-no-object-as-map)] Don't construct an `Immutable.Map` |
| 42 | + with an object-as-map. |
41 | 43 | * [[link](#react-function-prop-defaults)] Don't use React
|
42 | 44 | `defaultProps` for function components.
|
43 | 45 | * [Internal to Zulip and our codebase](#zulip)
|
@@ -542,6 +544,26 @@ in Flow, or a design limitation of Flow, or an issue in the Flow types
|
542 | 544 | provided by Immutable.js, or some combination.)
|
543 | 545 |
|
544 | 546 |
|
| 547 | +<div id="immutable-no-object-as-map" /> |
| 548 | + |
| 549 | +**Don't construct an `Immutable.Map` with an object-as-map**: Whenever you |
| 550 | +create a non-empty `Immutable.Map`, pass an array of entries instead of an |
| 551 | +object-as-map. For example: |
| 552 | +```js |
| 553 | +Immutable.Map([[HOME_NARROW_STR, [1, 2]]]) // good |
| 554 | + |
| 555 | +Immutable.Map({ [HOME_NARROW_STR]: [1, 2] }) // BAD -- don't do |
| 556 | +``` |
| 557 | + |
| 558 | +This is essential in order to get effective type-checking of the value |
| 559 | +passed to the `Immutable.Map` function when a key is computed (like |
| 560 | +`HOME_NARROW_STR`) instead of literal (like 'foo'). In the Immutable type |
| 561 | +definition, the object-as-map branch involves an object type with an indexer |
| 562 | +property, and in general [Flow seems to have trouble with those][]. |
| 563 | + |
| 564 | +[Flow seems to have trouble with those]: https://chat.zulip.org/#narrow/stream/243-mobile-team/topic/.60Immutable.2EMap.28.7B.20.5BSTRING_CONST.5D.3A.20.E2.80.A6.20.7D.29.60.20busted.20by.20Flow.20bug/near/1481088 |
| 565 | + |
| 566 | + |
545 | 567 | <div id="react-function-prop-defaults" />
|
546 | 568 |
|
547 | 569 | **Don't use React `defaultProps` for function components**:
|
|
0 commit comments