Skip to content

Return type of exported function has or is using name 'IMemoized' from external module "lru-memoizer" but cannot be named #10

@aschekatihin

Description

@aschekatihin

Error in new Typescript 3.4:

clwy-node-jwks-rsa/wrappers/cache.ts(7,17): error TS4058: Return type of exported function has or is using name 'IMemoized' from external module "lru-memoizer" but cannot be named.

Example (from clwy-node-jwks-rsa):

export function cacheSigningKey(client: JwksClient, cacheMaxEntries: number = 5, options = {cacheMaxAge: ms('10h') }) {
  const logger = debug('jwks');
  const getSigningKey = client.getSigningKey.bind(client);

  logger(`Configured caching of singing keys. Max: ${cacheMaxEntries} / Age: ${options.cacheMaxAge}`);

  return memoizer({
    load: (kid, callback) => {
      getSigningKey(kid, (err, key) => {
        if (err) {
          return callback(err);
        }

        logger(`Caching signing key for '${kid}':`, key);
        return callback(null, key);
      });
    },
    hash: kid => kid,
    maxAge: options.cacheMaxAge,
    max: cacheMaxEntries
  });
}

As interfaces aren't really exported in typings - typescript guesses return type correctly as IMemoized here but cannot really use it.

So, as temporary fix

export function cacheSigningKey(client: JwksClient, cacheMaxEntries: number = 5, options = {cacheMaxAge: ms('10h') }): any {

works, but type info is obviously lost

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions