diff --git a/types/index.d.ts b/types/index.d.ts index 13da7ab..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: InstanceType, - 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[]): boolean; + 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[]): boolean; + 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>; +}