Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
user status types: Say that /register response data is string-keyed
All JS objects are string-keyed; see Greg's explanation at zulip#5224 (comment) For convenience, Flow has some support for object indexer types that aren't subtypes of `string`. But Flow doesn't yet support numeric literal property keys; see facebook/flow#380 and https://flow.org/try/#0C4TwDgpgBAsiDyAjAVlAvFA3gHygbQDsBXAW0QgCcBdALikQHsGAbCAQwKmwF8AoXgMYMCAZ2BQ2dOElQZMUAIx1gFItG4BuKAHptUAHLCAtGIoBLAgHMozM8EptmUMBQaQKoKAGsIIEVAIGcREiMDAGDwgAEwA6fCJRUPDIqJMQAmA2AA8qIA That'd make it hard to construct valid test data for this part of the /register response in a way that Flow can track, when we start type-checking userStatusReducer's test file soon. At least, it'd make it hard to use literal values to construct test data. It'd be tempting to use a workaround mentioned in that Flow issue, facebook/flow#380 (comment) : ``` var x = { [1234]:"a", [5678]:"b" } ``` but then it seems we'd silently lose type-checking of the values at numeric keys in the object; see https://flow.org/try/#0C4TwDgpgBAsiDyAjAVlAvFA3gHygbQDsBXAW0QgCcBdALikQHsGAbCAQwKmwF8AoXgMYMCAZ2BQ2dOElQZM+AIy0oAcgBmTFVG4BuKAHp9UAMoALBkWYATKJQoMKUABTrNUAJYiCK8W3pNWDgBCAEogA : ``` type MyObj = {| [number]: boolean |} // Should error ('foo' isn't a boolean!) const a: MyObj = { [1]: 'foo' }; ``` Fortunately, I don't think there's a downside to saying the properties are strings here. This type no longer has anything to do with the type we use for our internal "user status" model. It's just a read-only data object whose keys we'll read one by one, to inform how the model updates on a REGISTER_COMPLETE. All of JavaScript's built-in methods for reading an object's keys (e.g., Object.keys) give the keys as strings, that we'll have to call makeUserId(parseInt(…)) on.
- Loading branch information