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

ExtractReturn type is any #7071

Closed
dfroger opened this issue Oct 21, 2018 · 5 comments
Closed

ExtractReturn type is any #7071

dfroger opened this issue Oct 21, 2018 · 5 comments

Comments

@dfroger
Copy link

dfroger commented Oct 21, 2018

I have problem with the ExtractReturn helper as reproduced in this example code.

In redux.js, action has type any, while it should be the returned type of foo.

Tested with flow 0.83.0, there is no error message.

Thanks for your yelp.

actions.js:

// @flow

import type { A } from './a';

import * as actions from './actions';

export type ExtractReturn<Fn> = $Call<<T>((...Iterable<any>) => T) => T, Fn>;

export const FOO: 'FOO' = 'FOO';
export const BAR: 'BAR' = 'BAR';

export const foo = () => ({
    type: FOO,
    foo: 42
})

export const bar = () => ({
    type: BAR,
    bar: 42
})

export type Action =
    | ExtractReturn<typeof actions.bar>
    | ExtractReturn<typeof actions.foo>;

a.js:

// @flow

import * as actionTypes from './actions';
import type { Action } from './actions';

export type A = string;

export const reducer = (action: Action) => action.type === actionTypes.FOO ? 1 : 2;

redux.js:

// @flow

import * as actionTypes from './actions';
import type { Action } from './actions';

export const reducer = (action: Action) => {
    if (action.type === actionTypes.FOO) console.log(action.x);  // action is typed any here
};
@MartinCerny-awin
Copy link

MartinCerny-awin commented Oct 28, 2018

I am having the same issue and it looks like that it is related to import bug mentioned in #6797 (comment) and probably to #4312

When I use type extracted using ExtractReturn in the same file it is correctly typed, but when I import it in the different file, it is exported as any.

@dfroger
Copy link
Author

dfroger commented Oct 29, 2018

@MartinCerny-awin Thanks for this very usefull feedback! I'll keep an eye on these issues...

@Eugene-Musika
Copy link

It works if add * as return type to foo and bar actions like so:

export const foo = (): * => ({
    type: FOO,
    foo: 42
})

export const bar = (): * => ({
    type: BAR,
    bar: 42
})

Hope it will help someone.
But still I think it's a bug. And it reproduces even in v0.109.0

@dfroger
Copy link
Author

dfroger commented Nov 14, 2019

Interessing! By the way, I didn't updated this issue, as I'm no more working on web development.

@SamChou19815
Copy link
Contributor

We now have ReturnType

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

4 participants