JavaScript

JavaScript

Made by DeepSource

Indexers must be declared with key name JS-0495

Type check
Minor

Adding keys to the indexers is considered a good practice and is preferred because an object will likely have properties added to it and retrieved throughout its lifecycle. Furthermore, the property keys may not even be known statically, so writing out a type annotation would not be possible. Flow provides a special property for objects like these, called an "indexer property". An indexer property allows reads and writes using any key that matches the indexer key type.

Bad Practice

type city = { [string]: number };
type country = { [Coordinates]: number };
type zip = { [ string | boolean]: number, };

Recommended

type city = { [key: string]: number };
type country = { [x : Coordinates]: number };
type zip = { [z :  string | boolean]: number, };