auth0-spa-js icon indicating copy to clipboard operation
auth0-spa-js copied to clipboard

Implicit return in auth0-spa-js/src/cache /cache-manager.ts when TS "noImplicitReturns" is set to true

Open denniscalazans opened this issue 1 year ago • 4 comments

Checklist

Description

private async getCacheKeys(): Promise<string[] | undefined> { if (this.keyManifest) { return (await this.keyManifest.get())?.keys; } else if (this.cache.allKeys) { return this.cache.allKeys(); } }

Reproduction

Install Auth0 library

  • npm i --save @auth0/auth0-spa-js

  • Make use of it

  • npm run build the angular project

✘ [ERROR] TS7030: Not all code paths return a value. [plugin angular-compiler]

    ../../node_modules/@auth0/auth0-spa-js/src/cache/cache-manager.ts:156:32:
      156 │   private async getCacheKeys(): Promise<string[] | undefined> {
          ╵                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Additional context

No response

auth0-spa-js version

2.1.3

Which framework are you using (React, Angular, Vue...)?

Angular

Framework version

17

Which browsers have you tested in?

Other

denniscalazans avatar Jun 21 '24 13:06 denniscalazans

Hello @denniscalazans ,

I am not seeing the error you mentioned when I use [email protected] along with [email protected]. Can you share your package.json here ?

Additionally, could you provide a code snippet demonstrating how you are using [email protected] ?. This would be helpful.

nandan-bhat avatar Jun 26 '24 15:06 nandan-bhat

I'm having the same problem. We've implemented our own ICache, and configured that in Auth0.config.cache. That seems to cause it, reverting back and using the default 'memory' or 'localstorage' option does not cause this error to occur.

sanvisser avatar Jul 04 '24 14:07 sanvisser

I've set "noImplicitReturns": false in our own tsconfig.json to fix this but that is less than ideal

sanvisser avatar Jul 04 '24 14:07 sanvisser

Was caused by a direct import from @auth0/auth0-spa-js/src/cache/shared instead of @auth0/auth0-spa-js in our repo.

The MaybePromise return type is not re-exported by @auth0/auth0-angular, so that might be why some people are running into this problem when implementing their own Cache. I think some editors will attempt to directly import that type from @auth0/auth0-spa-js/src/cache/shared when @auth0/auth0-spa-js is not in the package.json, because it is a dependency of @auth0/auth0-angular.

Ionaru avatar Jul 09 '24 13:07 Ionaru