Skip to content

Function inside generic function doesn't work #227

@itryapitsin2

Description

@itryapitsin2

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions