question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Types: DismissReason enum

See original GitHub issue

Current behavior

When a SweetAlertResult is returned with a DismissReason, the dismiss reason is a string. However, the Swal.DismissReason type is a standard typescript enum, implying that it will be a number

Expected behavior

The Swal.DismissReason enum declaration would be a string enum

enum DismissReason {
  cancel = 'cancel',
  backdrop = 'backdrop',
  close = 'close',
  esc = 'esc',
  timer = 'timer'
}

Live demo

https://tasteful-spectrum.glitch.me

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
Basaingealcommented, Aug 19, 2019

Alright. Thanks for the information. I ran some tests using the declaration file, and you’re right, the evaluations work out.

I’m working on a library that needs to serialize these results to JSON strings, so some of my type conversions were not going as expected, but I think I can sort it out now based on the information provided.

Thank you.

1reaction
toveruxcommented, Aug 19, 2019

Would not dismiss == Swal.DismissReason.cancel be transpiled to dismiss == 0 which would evaluate to false?

No, don’t worry, .d.ts files never have any kind of influence on the emitted code. The enum itself and its values are always coming from the SweetAlert source, that is JavaScript. A .d.ts file cannot bear any actual value that can be used at runtime. That’s pure types.

Also, I don’t mean to doubt you, but just changing the enum to a string enum in the sweetalert2.d.ts seems to work fine for me.

That is possible, however (that’d still be types… no matter what values you put in the enum members, at runtime that’ll still be what SweetAlert declared). I said that by memory, so I’m not sure, you may be right. In that case that would fix comparison with simple strings.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Enums - GitHub Docs
Enums represent possible sets of values for a field. For example, the Issue object has a field called state . The state is...
Read more >
Typescript error This condition will always return 'true' since ...
With the above solution, there is no IDE error, but the condition never true, as the enum[value] give a numeric value. The next...
Read more >
Schema | GitHub@current | Studio - Apollo Studio
All Directives All Return Types All Arguments. DismissReason. The possible reasons that a Dependabot alert was dismissed. Kind of type: Enum ...
Read more >
This condition will always return 'false' since the types have no ...
The error "This condition will always return 'false' since the types have no overlap" occurs when a condition is guaranteed to have the...
Read more >
Recreating advanced Enum types in Typescript | by Nitzan Hen
Guide to creating pseudo enums in Typescript. ... In essence, enums (or enumeration types, to be more descriptive) can be thought of like...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found