Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function inside generic function doesn't work #227

Open
3 of 10 tasks
itryapitsin2 opened this issue Mar 15, 2019 · 0 comments
Open
3 of 10 tasks

Function inside generic function doesn't work #227

itryapitsin2 opened this issue Mar 15, 2019 · 0 comments

Comments

@itryapitsin2
Copy link

This is a:

  • Bug Report
  • Feature Request
  • Question
  • Other

Which concerns:

  • flow-runtime
  • babel-plugin-flow-runtime
  • flow-runtime-validators
  • flow-runtime-mobx
  • flow-config-parser
  • The documentation website

What is the current behaviour?

type ActionTypes = { ... };
type THandlers<TState, TAction: ActionTypes> = {
    [key: string]: (state: TState, action: TAction) => TState
};

type TReducer<TState, TAction: ActionTypes> = (state: TState, action: TAction) => TState;

export default function createReducer<TState, TAction: ActionTypes>(
    initialState: TState,
    handlers: THandlers<TState, TAction>,
): TReducer<TState, TAction> {
    return function reducer(state: TState = initialState, action: TAction): TState {
        if (handlers[action.type]) {
            return handlers[action.type](state, action);
        }
        return state;
    };
}

This code throws exception that TAction and TState is not defined in line

return function reducer(state: TState = initialState, action: TAction): TState {

If change this codeline to

return function reducer(state: * = initialState, action: *): * {

then exception is missing and code works.


What is the expected behaviour?

Should work correctly.
Works fine without flow-runtime.


Which package versions are you using?

flow-runtime version: 0.17.0
babel-plugin-flow-runtime version: 0.18.0

@itryapitsin2 itryapitsin2 changed the title Generic function doesn't work Function inside generic function doesn't work Mar 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant