EnumCase with Infinity not supported
Tried to convert pdf-lib: https://www.npmjs.com/package/pdf-lib ts2fable node_modules/pdf-lib/cjs/index.d.ts pdfLib.fs -e pdf-lib
export declare enum ParseSpeeds { Fastest = Infinity, Fast = 1500, Medium = 500, Slow = 100 }
I locally set: Fastest = 100000 to skip that error
I don't think we can set an enum with Inifity as a value in F#.
How is Fastest = Infinity represented at runtime by TypeScript?
I assume it's the same as Number.POSITIVE_INFINITY, so we can represent it in F# as System.Double.PositiveInfinity, though unfortunately it's not supported in enums. This code doesn't compile (literal floats are not supported either):
type ParseSpeeds =
| Fastest = System.Double.PositiveInfinity
| Fast = 1500
| Medium = 500
| Slow = 100
I'm thinking now that we added CompiledValue to support TypescriptTaggedUnions when the tag was not a string. In a similar fashion, maybe we could extend Emit support to enums/unions so you could write:
type ParseSpeeds =
| [<Emit("Infinity")>] Fastest = 100000000 // Dummy number
| Fast = 1500
| Medium = 500
| Slow = 100
Thanks for checking, yes that's a good fix.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Infinity
Infinity is a property of the global object. In other words, it is a variable in global scope.
The initial value of Infinity is Number.POSITIVE_INFINITY. The value Infinity (positive infinity) is greater than any other number.