Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TokenStatus enum doesn't exist at runtime #238

Open
franklin-ross opened this issue Mar 1, 2024 · 0 comments
Open

TokenStatus enum doesn't exist at runtime #238

franklin-ross opened this issue Mar 1, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@franklin-ross
Copy link

franklin-ross commented Mar 1, 2024

Describe the bug

Your types have declare enum TokenStatus but you don't have any Javascript to implement that enum so users will break if they try to do token.status === Square.TokenStatus.OK. You should either implement the enum correctly in JS or use a union of string literal types as the type for token.status and remove the enum type entirely.

To Reproduce

Run some code that does a comparison like:

import * as Square from '@square/web-sdk'

const token = getMeAToken();

if (token.status === Square.TokenStatus.OK) {
  console.log("Everything is fine");
}

Note that token.status === "OK" is technically invalid Typescript (and for most other languages) as a string value that happens to match an enum value isn't technically the same as the enum value.

Expected behavior

  • An enum defined using Typescript functions like an enum in JS.
  • A field uses a string literal union if it actually expects a specific set of string values.

Screenshots

Not applicable.

Desktop (please complete the following information):

  • OS: Any
  • Browser: Anything that runs Javascript
  • Version: Anything that runs Javascript

Smartphone (please complete the following information):

Again, anything that runs Javascript.

Additional context

You probably just want to make this change in payment-method-types.d.ts:

// ...

interface TokenResult {
    /**
     * Indicates whether the tokenization request was successful.
     */
    status: "Unknown" | "OK" | "Error" | "Invalid" | "Abort" | "Cancel";

    // ...
}

// ...

Or, again, implement the enum correctly in your JS. If you built from Typescript originally, perhaps you mistakenly used a const enum or something? 🤷‍♀️

@franklin-ross franklin-ross added the bug Something isn't working label Mar 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant