Skip to content

Commit 2219c1d

Browse files
authored
[bug] Fix types for prime() to allow priming an Error (#217)
1 parent 54216e3 commit 2219c1d

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,7 @@ Primes the cache with the provided key and value. If the key already exists, no
344344
change is made. (To forcefully prime the cache, clear the key first with
345345
`loader.clear(key).prime(key, value)`.) Returns itself for method chaining.
346346

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

348349
## Using with GraphQL
349350

src/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ declare class DataLoader<K, V, C = K> {
5656
* Adds the provied key and value to the cache. If the key already exists, no
5757
* change is made. Returns itself for method chaining.
5858
*/
59-
prime(key: K, value: V): this;
59+
prime(key: K, value: V | Error): this;
6060
}
6161

6262
declare namespace DataLoader {

src/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,10 @@ class DataLoader<K, V, C = K> {
172172
/**
173173
* Adds the provided key and value to the cache. If the key already
174174
* exists, no change is made. Returns itself for method chaining.
175+
*
176+
* To prime the cache with an error at a key, provide an Error instance.
175177
*/
176-
prime(key: K, value: V): this {
178+
prime(key: K, value: V | Error): this {
177179
var cache = this._promiseCache;
178180
if (cache) {
179181
var cacheKey = getCacheKey(this._options, key);

0 commit comments

Comments
 (0)