• Robert Knight's avatar
    Infer store module types automatically · 987bcfa5
    Robert Knight authored
    Remove the need to define the type of store created by each module
    manually by adding a `StoreFromModule` helper in `create-store.js` which
    can infer the store type from a store module configuration. Using this
    the type of a store composed from several modules can then be created
    with:
    
    ```
    import fooModule from './modules/foo';
    import barModule from './modules/bar';
    
    // Define type of store returned by `createStore([fooModule, barModule])`
    /** @typedef {StoreType<fooModule> & StoreType<barModule>} AppStore */
    ```
    
    Ideally `createStore` would just infer the type based upon its
    arguments. I haven't worked out how to do that yet. Nevertheless, this
    still removes the need for a lot of manually defined types.
    
    To ensure more useful error messages from TS if a store module's configuration
    has the wrong shape a `storeModule` helper has been added. This wraps
    the configuration for each module to check its shape before the
    individual modules are combined into one type for the store. This helper could
    also perform runtime validation in future.
    
     - Add `StoreFromModule` type in `create-store.js` and several helpers
       to support it
     - Modify each store module to wrap the export in `storeModule` and
       remove any manually defined store types
    987bcfa5
selection.js 10 KB