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

EnumCase with Infinity not supported #444

Open
Nexus452 opened this issue Aug 7, 2022 · 3 comments
Open

EnumCase with Infinity not supported #444

Nexus452 opened this issue Aug 7, 2022 · 3 comments

Comments

@Nexus452
Copy link

Nexus452 commented Aug 7, 2022

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

@MangelMaxime MangelMaxime changed the title EnumCase not supported EnumCase with Infinity not supported Aug 7, 2022
@MangelMaxime
Copy link
Member

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?

@alfonsogarciacaro
Copy link
Member

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

@Nexus452
Copy link
Author

Nexus452 commented Aug 9, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants