- 
                Notifications
    
You must be signed in to change notification settings  - Fork 13.1k
 
Closed
Labels
Design LimitationConstraints of the existing architecture prevent this from being fixedConstraints of the existing architecture prevent this from being fixed
Description
TypeScript Version: 3.6.3+
Search Terms:
createModel
[model example]
// A *self-contained* demonstration of the problem follows...
// Test this by running `tsc` on the command-line, rather than through another build tool such as Gulp, Webpack, etc.
export interface Reducers<M> {
  [doSomething: string]:
    | (<P extends never>(state: Readonly<M>, action: P) => M)
    | (<P extends AbstractAction>(state: Readonly<M>, action: P) => M);
}
export default function createModel<M, R extends Reducers<M>, E extends Effects>(model: {
  namespace: string;
  state: M;
  reducers: R;
  effects?: E;
}) {
...
}
const model = createModel({
  namespace: 'model',
  state: modelWithEffectsState,
  reducers: {
    doSomething: (state, action: { id: number }) => ({ ...state })
  },
  effects: {
  }
});
const { actions } = model;
actions.doSomething({ id: 1 });Expected behavior:
from 3.3.+ to 3.5.,
while invoking createModel, the pass-in object's properties state's type determines reducers['doSomething'] first argument's type and its type is the type of  modelWithEffectsState,
and reducers['doSomething'] second argument's type is the type of model.actions.doSomething's argument type  - really wonderful features by generic and type inference
Actual behavior:
while since 3.6.3  reducers['doSomething'] first argument's type becomes any,
is there any way to recover these features, or changes i can make to make createModel works again?
help needed
Playground Link:
Related Issues:
Metadata
Metadata
Assignees
Labels
Design LimitationConstraints of the existing architecture prevent this from being fixedConstraints of the existing architecture prevent this from being fixed