gajus / gajus/flow-runtime

Function inside generic function doesn't work

Open
#227 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
797
Forks
49
PR merge metrics
No merged PRs in 30d

Description

This is a:

- [x] Bug Report
- [ ] Feature Request
- [ ] Question
- [ ] Other

Which concerns:

- [x] flow-runtime
- [x] 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 = {
[key: string]: (state: TState, action: TAction) => TState
};

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

export default function createReducer(
initialState: TState,
handlers: THandlers,
): TReducer {
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

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.