Skip to content

Commit

Permalink
[bug] Fix types for prime() to allow priming an Error (#217)
Browse files Browse the repository at this point in the history
  • Loading branch information
leebyron committed Nov 14, 2019
1 parent 54216e3 commit 2219c1d
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
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

0 comments on commit 2219c1d

Please sign in to comment.