Generic is not resolving properly in complex situation.
- Dominant language
- Rust
- Stars
- 22.3k
- Forks
- 1.9k
- PR merge metrics
- No merged PRs in 30d
Description
Hi,
I am trying to create a "middleware" api, in redux, which already has a bunch of built-in types. And I am trying to use existing types to create a new middleware. But `flow` is throwing this error to me:
```
store.dispatch({ type: 'string' });
^ object literal. This type is incompatible with the expected param type of
14: return (store: MiddlewareAPI) => next => (action: A) => {
^ some incompatible instantiation of `A`
```
When I am trying to do:
```js
/* @flow */
declare type DispatchAPI = (action: A) => A;
declare type Dispatch }> = DispatchAPI;
declare type MiddlewareAPI> = {
dispatch: D;
getState(): S;
};
type Middleware> =
(api: MiddlewareAPI) =>
(next: D) => D;
export const createSSRMiddleware = (): Middleware => {
return (store: MiddlewareAPI) => next => (action: A) => {
store.dispatch({ type: 'string' });
return next(action);
};
};
```
Below is the link to reproduce the issue:
https://flow.org/try/#0PQKgBAAgZgNg9gdzCYAoVATApgYxgQwCcswAXATwAcSARASwGdL9ScALAQQAUBJAHg4A+MAF4wACnw5SdOADsAXGA4BKUcI4BuTLgLEyVWo2as2ApQG8D1JQBIAygFcARhWp8GpQnTkBzYQC+wmL0TCzs3PxC2th4RCRuJACydBgYMFgI8ZF89gA0ygU0omChJuwCgsFgFqhg9WAYxuFsSjTaDWC+WKT2pCxY4ipK9toB2olgKWkZWcS5BRxFJWUtlcF1DZKUdErT6ZnZvAuFpYJqIoKbneJyWAAepG0Xwu3oD5RwhKRgOPKev2IA3s9gASvtZvESicOJZrFglJ5vH4wEEhntUgc5lgYcFhLVOsRSI5CHIJJ4vgippjIcQcvllOd1GA7o9mZJpLJFMoXjVrp0wBTiAA6JphUziKyJJQAciRPl8MtRKg6AvqRJJZNZpA5MnkKv541QRqAA
I also found out that even with a simple case like:
```js
/* @flow */
const foo = () => {
const bar: A = 1;
}
```
It also producing the same error, I don't know if they are related. But looks like it's the case.
Contributor guide
Assessment
This issue has not been assessed yet.