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

Allow specific CacheMap key type #145

Merged
merged 2 commits into from
Nov 13, 2019
Merged

Conversation

AdamHerrmann
Copy link
Contributor

@AdamHerrmann AdamHerrmann commented Apr 26, 2018

I would like to be able to use both the cacheKeyFn and cacheMap options in typescript. Currently the following fails to compile because CacheMap has the wrong key type:

interface Id {
  id: string;
}

const loader = new Dataloader<Id, Id>(async i => i, {
  cacheKeyFn: (k: Id) => k.id,
  cacheMap: new Map<string, Promise<Id>>(),
});

This change allows the following:

const loader = new Dataloader<Id, Id, string>(async i => i, {
  cacheKeyFn: (k: Id) => k.id,
  cacheMap: new Map<string, Promise<Id>>(),
});

I'm fairly certain this change is backward compatible, so this should continue to work:

const loader = new Dataloader<Id, Id>(async i => i);

Fixes #197

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 3cdad8a on AdamHerrmann:fix/types into 420e62f on facebook:master.

@leebyron
Copy link
Contributor

Coverage failure is related to #210. This change dropped the total number of lines of code so coverage percentage went down

@leebyron leebyron merged commit bf23eb9 into graphql:master Nov 13, 2019
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

Successfully merging this pull request may close these issues.

3 participants