Types: DismissReason enum
See original GitHub issueCurrent 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
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (5 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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.
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.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.