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

Flow error on flow version 113 #20

Open
TJTorola opened this issue Jul 10, 2020 · 6 comments
Open

Flow error on flow version 113 #20

TJTorola opened this issue Jul 10, 2020 · 6 comments

Comments

@TJTorola
Copy link

I'm running into the following flow errors when running on version 113. Similar code on another repo with version 84 is passing just fine.

yarn run v1.22.4
$ flow
Error ------------------------------------------------------------- node_modules/typed-actions/types/index.js.flow:60:35

Missing type annotation for `A`. `A` is a type parameter declared in function type [1] and was implicitly instantiated
at `$ObjMap` [2].

   node_modules/typed-actions/types/index.js.flow:60:35
                                         v-----------------------------
   60| export type Actions<Collection> = $ObjMap<$ObjMapi<Collection, <
   61|   K, V, R, A, B, C,
   62| >(K, V) => $Call<
   63|   & (((...args: [A, B, C]) => R) => (A, B, C) => Action<K, R>)
   64|   & (((...args: [A, B]) => R) => (A, B) => Action<K, R>)
   65|   & (((...args: [A]) => R) => (A) => Action<K, R>)
   66| , V>>, typeof locate>
       --------------------^ [2]

References:
   node_modules/typed-actions/types/index.js.flow:30:24
                              v----------------------
   30| declare function locate<A, B, C, D, E, F, R>((
   31|   A | (B & void),
   32|   C | (D & void),
   33|   E | (F & void),
   34| ) => R): ((
   35|   A | (void & null & empty),
   36|   C | (void & null & empty),
   37|   E | (void & null & empty),
   38| ) => R)
       -----^ [1]


Error ------------------------------------------------------------- node_modules/typed-actions/types/index.js.flow:60:35

Missing type annotation for `C`. `C` is a type parameter declared in function type [1] and was implicitly instantiated
at `$ObjMap` [2].

   node_modules/typed-actions/types/index.js.flow:60:35
                                         v-----------------------------
   60| export type Actions<Collection> = $ObjMap<$ObjMapi<Collection, <
   61|   K, V, R, A, B, C,
   62| >(K, V) => $Call<
   63|   & (((...args: [A, B, C]) => R) => (A, B, C) => Action<K, R>)
   64|   & (((...args: [A, B]) => R) => (A, B) => Action<K, R>)
   65|   & (((...args: [A]) => R) => (A) => Action<K, R>)
   66| , V>>, typeof locate>
       --------------------^ [2]

References:
   node_modules/typed-actions/types/index.js.flow:30:24
                              v----------------------
   30| declare function locate<A, B, C, D, E, F, R>((
   31|   A | (B & void),
   32|   C | (D & void),
   33|   E | (F & void),
   34| ) => R): ((
   35|   A | (void & null & empty),
   36|   C | (void & null & empty),
   37|   E | (void & null & empty),
   38| ) => R)
       -----^ [1]


Error ------------------------------------------------------------- node_modules/typed-actions/types/index.js.flow:60:35

Missing type annotation for `E`. `E` is a type parameter declared in function type [1] and was implicitly instantiated
at `$ObjMap` [2].

   node_modules/typed-actions/types/index.js.flow:60:35
                                         v-----------------------------
   60| export type Actions<Collection> = $ObjMap<$ObjMapi<Collection, <
   61|   K, V, R, A, B, C,
   62| >(K, V) => $Call<
   63|   & (((...args: [A, B, C]) => R) => (A, B, C) => Action<K, R>)
   64|   & (((...args: [A, B]) => R) => (A, B) => Action<K, R>)
   65|   & (((...args: [A]) => R) => (A) => Action<K, R>)
   66| , V>>, typeof locate>
       --------------------^ [2]

References:
   node_modules/typed-actions/types/index.js.flow:30:24
                              v----------------------
   30| declare function locate<A, B, C, D, E, F, R>((
   31|   A | (B & void),
   32|   C | (D & void),
   33|   E | (F & void),
   34| ) => R): ((
   35|   A | (void & null & empty),
   36|   C | (void & null & empty),
   37|   E | (void & null & empty),
   38| ) => R)
       -----^ [1]


Error ------------------------------------------------------------- node_modules/typed-actions/types/index.js.flow:60:43

Missing type annotation for `K`. `K` is a type parameter declared in function type [1] and was implicitly instantiated
at `$ObjMapi` [2].

   node_modules/typed-actions/types/index.js.flow:60:43
                                                 v---------------------
   60| export type Actions<Collection> = $ObjMap<$ObjMapi<Collection, <
   61|   K, V, R, A, B, C,
   62| >(K, V) => $Call<
   63|   & (((...args: [A, B, C]) => R) => (A, B, C) => Action<K, R>)
   64|   & (((...args: [A, B]) => R) => (A, B) => Action<K, R>)
   65|   & (((...args: [A]) => R) => (A) => Action<K, R>)
   66| , V>>, typeof locate>
       ----^ [2]

References:
   node_modules/typed-actions/types/index.js.flow:60:64
                                                                      v
   60| export type Actions<Collection> = $ObjMap<$ObjMapi<Collection, <
   61|   K, V, R, A, B, C,
   62| >(K, V) => $Call<
   63|   & (((...args: [A, B, C]) => R) => (A, B, C) => Action<K, R>)
   64|   & (((...args: [A, B]) => R) => (A, B) => Action<K, R>)
   65|   & (((...args: [A]) => R) => (A) => Action<K, R>)
   66| , V>>, typeof locate>
       ---^ [1]


Error ------------------------------------------------------------- node_modules/typed-actions/types/index.js.flow:60:43

Missing type annotation for `R`. `R` is a type parameter declared in function type [1] and was implicitly instantiated
at `$ObjMapi` [2].

   node_modules/typed-actions/types/index.js.flow:60:43
                                                 v---------------------
   60| export type Actions<Collection> = $ObjMap<$ObjMapi<Collection, <
   61|   K, V, R, A, B, C,
   62| >(K, V) => $Call<
   63|   & (((...args: [A, B, C]) => R) => (A, B, C) => Action<K, R>)
   64|   & (((...args: [A, B]) => R) => (A, B) => Action<K, R>)
   65|   & (((...args: [A]) => R) => (A) => Action<K, R>)
   66| , V>>, typeof locate>
       ----^ [2]

References:
   node_modules/typed-actions/types/index.js.flow:60:64
                                                                      v
   60| export type Actions<Collection> = $ObjMap<$ObjMapi<Collection, <
   61|   K, V, R, A, B, C,
   62| >(K, V) => $Call<
   63|   & (((...args: [A, B, C]) => R) => (A, B, C) => Action<K, R>)
   64|   & (((...args: [A, B]) => R) => (A, B) => Action<K, R>)
   65|   & (((...args: [A]) => R) => (A) => Action<K, R>)
   66| , V>>, typeof locate>
       ---^ [1]



Found 5 errors
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

The code that I am adding that is triggering the issue is as follows:

// @flow
import { action, createActions, handleActions } from 'typed-actions';

const LOAD_THREAD_DATA = '@threads/LOAD_THREAD_DATA';

const actions = createActions({
  [LOAD_THREAD_DATA]: (threadId: string) => action({ threadId }),
});

type Actions = typeof actions;

export const loadThreadData = actions[LOAD_THREAD_DATA];

I'll probably take a stab at seeing if I can correct the flowtypes (if that is actually the issue) but it's a bit over my head.

@TJTorola
Copy link
Author

TJTorola commented Jul 10, 2020

Oh, one more thing. Oddly, when I export the Actions type it adds the following error as well:

Error ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ react/store/threads.js:6:17

Missing type annotation for A. A is a type parameter declared in function type [1] and was implicitly instantiated at
call of createActions [2].

     react/store/threads.js
      3│
      4│ const LOAD_THREAD_DATA = '@threads/LOAD_THREAD_DATA';
      5│
 [2]  6│ const actions = createActions({
      7│   [LOAD_THREAD_DATA]: (threadId: string) => action({ threadId }),
      8│ });
      9│
     10│ export type Actions = typeof actions;
     11│

     node_modules/typed-actions/actions/index.js.flow
 [1] 12│   : <A: Object>(A) => Actions<A>

Not sure if it's related.

@TJTorola
Copy link
Author

TJTorola commented Jul 13, 2020

Adding any to the createActions call supresses the errors, but also pretty much removes all of the type info from the library.

// @flow
import { action, createActions, handleActions } from 'typed-actions';

const LOAD_THREAD_DATA = '@threads/LOAD_THREAD_DATA';

const actions = createActions<any>({
  [LOAD_THREAD_DATA]: (threadId: string) => action({ threadId }),
});

type Actions = typeof actions;

export const loadThreadData = actions[LOAD_THREAD_DATA];

@TJTorola
Copy link
Author

Also potentially related: https://medium.com/flow-type/asking-for-required-annotations-64d4f9c1edf8. Maybe it is no longer possible for this to be implicitly typed?

@lttb
Copy link
Owner

lttb commented Jul 16, 2020

Hi @TJTorola, thank you for the issue!

And excuse me for delay please.

Also potentially related: https://medium.com/flow-type/asking-for-required-annotations-64d4f9c1edf8. Maybe it is no longer possible for this to be implicitly typed?

That's right!

Although all the types are strictly defined, there are problems with types resolution from 0.85.
I've experimented with some workarounds (and I'll try to prepare the release of that), but it seems that the best way to solve this problem is by a bit different interface, that I'm also thinking to release.

Just a simple example of the idea

export type User = { name?: string, id: string, offers?: Offer[] };

export const user = createActions("@namespace/USER", {
    get: (id: string) => action(id),
    done: (user: User) => action(user),
});

user.done({ id: "1", name: "user" });

user.done({ name: "user" }); // expected error

export type Offer = { name: string, id: string, title: string };

export const offer = createActions("@namespace/OFFER", {
    get: (id: string) => action({ id }),
    done: (offer: Offer) => action(offer),
});

type State = { user: User };

const initialState = {}
export default handleActions<State>(initialState)(
    [user, {
        get: (state, { payload }) => ({ user: { id: payload } }),
        done: (state, { payload }) => ({ user: payload }),
    }],
    [offer, {
        done: ({ user }, { payload }) => ({
            user: {
                ...user,
                offers: [payload].concat(user.offers || []),
            },
        }),
    }],
);

@TJTorola
Copy link
Author

@lttb No problem for the delay. That interface looks nice! A bit of a change since we couldn't do something like export const userDone = user.done; without hitting the same errors, but seems like a worthy tradeoff to me, maybe even a bit nicer to have the actions bundled together. Thanks, I think that resolves the issue for me, we can just do createActions<any> until you are ready to release the changes.

@TJTorola
Copy link
Author

@lttb One followup thought on that pattern. In our particular app it is often useful to get the type of some specific action to be able to respond to it elsewhere, maybe in middleware or a different reducer. Would there be a way to pull that off with this new interface?

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

2 participants