From b3d5863f355edb0974c719e4329a923286dededc Mon Sep 17 00:00:00 2001 From: Jaime Leonardo Suncin Cruz Date: Wed, 18 May 2022 17:37:18 -0600 Subject: [PATCH] fix: amend typescript definition Closes kartikk221/cached-lookup#2 --- types/index.d.ts | 45 ++++++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/types/index.d.ts b/types/index.d.ts index be58d52..afe6a8a 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -1,69 +1,68 @@ -type LookupHandler = () => T | Promise +type LookupHandler = () => T | Promise; type SupportedTypes = string | number | boolean; -type SupportedArgumentTypes = SupportedTypes | SupportedTypes[]; -interface ValueRecord { - value: T, - updated_at: number -}; +interface ValueRecord { + value: T; + updated_at: number; +} -export default class CachedLookup { +export default class CachedLookup { /** * Creates a new CachedLookup instance with the specified lookup function. * The lookup function can be both synchronous or asynchronous. * - * @param {function(...(SupportedArgumentTypes|Array)):T} lookup + * @param {LookupHandler} lookup */ - constructor(lookup: LookupHandler) + constructor(lookup: LookupHandler); /** * Returns a cached value that is up to max_age milliseconds old for the provided set of arguments. * Falls back to a fresh value if the cache value is older than max_age. - * + * * @param {Number} max_age In Milliseconds - * @param {...(SupportedArgumentTypes)} args + * @param {Array} args * @returns {Promise} */ - cached(max_age: number, ...args: SupportedArgumentTypes): Promise; + cached(max_age: number, ...args: SupportedTypes[]): Promise; /** * Returns a fresh value and automatically updates the internal cache with this value for the provided set of arguments. * - * @param {...(SupportedArgumentTypes)} args + * @param {Array} args * @returns {Promise} */ - fresh(...args: SupportedArgumentTypes): Promise; + fresh(...args: SupportedTypes[]): Promise; /** * Expires the cached value for the provided set of arguments. * - * @param {...(SupportedArgumentTypes)} args + * @param {Array} args * @returns {Boolean} True if the cache value was expired, false otherwise. */ - expire(...args: SupportedArgumentTypes): bool; + expire(...args: SupportedTypes[]): boolean; /** * Returns whether a fresh value is currently being resolved for the provided set of arguments. * - * @param {...(SupportedArgumentTypes)} args + * @param {Array} args * @returns {Boolean} */ - in_flight(...args: SupportedArgumentTypes): bool; + in_flight(...args: SupportedTypes[]): boolean; /** * Returns the last value update timestamp in milliseconds for the provided set of arguments. * - * @param {...(SupportedArgumentTypes)} args + * @param {Array} args * @returns {Boolean} */ - updated_at(...args: SupportedArgumentTypes): number | void; + updated_at(...args: SupportedTypes[]): number | void; /* CachedLookup Getters */ /** * Returns the underlying cache object which contains the cached values identified by their serialized arguments. * - * @returns {Map} + * @returns {Map>} */ - get cache(): Map; -} \ No newline at end of file + get cache(): Map>; +}