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

Export flow types (Options, CacheMap, and BatchLoadFn) #124

Closed
rwe opened this issue Dec 17, 2017 · 3 comments
Closed

Export flow types (Options, CacheMap, and BatchLoadFn) #124

rwe opened this issue Dec 17, 2017 · 3 comments

Comments

@rwe
Copy link

rwe commented Dec 17, 2017

The type definitions are helpful, but because they're not exported, it makes them difficult to use in composed APIs.

The only real change request here is to add export to those type definitions.

@erictt
Copy link

erictt commented Dec 19, 2017

If you are using flowtype, it probably will warn you when your CacheMap Class doesn't work.

@rwe
Copy link
Author

rwe commented Dec 20, 2017

My suggestion here isn't about lack of type checking, only that you can't reference those unexported types in your own declarations. Like:

import DataLoader from 'dataloader';

export default class MyDataLoader extends DataLoader<string, MyType> {
  constructor(someArg: string, options: /* what type declaration to put here? */) {
    super(someBatchLoadFn, options);
  }

  someHelperMethod(): void {
  }
}

If they were exported, then one could just:

import type {Options as DataLoaderOptions} from 'dataloader';

@Togrias
Copy link

Togrias commented Jan 2, 2018

Also, Flow seems to type-check incorrectly if you simply define:
type BatchLoadFn<K,V> = $ReadOnlyArray<K> => Promise<$ReadOnlyArray<V | Error>>

Somehow, Flow can't resolve (V | Error) properly. So new DataLoader(fn: BatchLoadFn) shows a warning.

The problem goes away if you modify the latest git commit to export the flow types and depend on those exported flow types.

But that seems like a bug with Flow rather than this.

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

3 participants