simple-oauth2 icon indicating copy to clipboard operation
simple-oauth2 copied to clipboard

Cannot use CredentialsEncodingMode in typescript

Open TimFroidcoeur opened this issue 2 years ago • 1 comments

I'm trying to use CredentialsEncodingMode.LOOSE, as follows:

import {ClientCredentials, AccessToken, CredentialsEncodingMode} from "simple-oauth2";
...
    this.oauth2 = new ClientCredentials(
        {
          client: {
            id: username,
            secret: password,
          },
          auth: {
            tokenHost: this.HOST,
            tokenPath: "/authentication/api/token",
          },
          options: {
            credentialsEncodingMode: CredentialsEncodingMode.LOOSE,
          },
        }
    );

and I get a runtime error

TypeError: Cannot read properties of undefined (reading 'LOOSE')

I'm not an expert in how typescript works, but according to https://ncjamieson.com/dont-export-const-enums/ this is an inherent limitation of exporting a const enum.

I am using the following as a workaround:

            // @ts-ignore
            credentialsEncodingMode: "loose",

maybe the exported enums should be non-const?

TimFroidcoeur avatar Mar 03 '23 14:03 TimFroidcoeur

Hey @TimFroidcoeur. We don't provide type definitions for this library, that means you are probably getting them from DefinitelyTyped. I'd open an issue/PR there instead.

jonathansamines avatar Mar 22 '23 03:03 jonathansamines