From 19474f5977f49828e5abdadf4e369266f408cdd5 Mon Sep 17 00:00:00 2001 From: Lee Byron Date: Thu, 14 Nov 2019 10:31:28 -0800 Subject: [PATCH] [bug] Fix types for prime() to allow priming an Error --- README.md | 1 + src/index.d.ts | 2 +- src/index.js | 4 +++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0dfbc16..369e6fa 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/index.d.ts b/src/index.d.ts index 4bb5cf4..d693354 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -56,7 +56,7 @@ declare class DataLoader { * 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 { diff --git a/src/index.js b/src/index.js index c12525f..f109d48 100644 --- a/src/index.js +++ b/src/index.js @@ -172,8 +172,10 @@ class DataLoader { /** * 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);