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

[BUG] Fix types for prime() to allow priming an Error #217

Merged
merged 1 commit into from Nov 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -344,6 +344,7 @@ Primes the cache with the provided key and value. If the key already exists, no
change is made. (To forcefully prime the cache, clear the key first with
`loader.clear(key).prime(key, value)`.) Returns itself for method chaining.

To prime the cache with an error at a key, provide an Error instance.

## Using with GraphQL

Expand Down
2 changes: 1 addition & 1 deletion src/index.d.ts
Expand Up @@ -56,7 +56,7 @@ declare class DataLoader<K, V, C = K> {
* Adds the provied key and value to the cache. If the key already exists, no
* change is made. Returns itself for method chaining.
*/
prime(key: K, value: V): this;
prime(key: K, value: V | Error): this;
}

declare namespace DataLoader {
Expand Down
4 changes: 3 additions & 1 deletion src/index.js
Expand Up @@ -172,8 +172,10 @@ class DataLoader<K, V, C = K> {
/**
* Adds the provided key and value to the cache. If the key already
* exists, no change is made. Returns itself for method chaining.
*
* To prime the cache with an error at a key, provide an Error instance.
*/
prime(key: K, value: V): this {
prime(key: K, value: V | Error): this {
var cache = this._promiseCache;
if (cache) {
var cacheKey = getCacheKey(this._options, key);
Expand Down