Skip to content

Cannot use CredentialsEncodingMode in typescript #429

@TimFroidcoeur

Description

@TimFroidcoeur

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions